Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript, ASP, and VB :)

Status
Not open for further replies.

JimmyFo

Programmer
Feb 14, 2005
102
US
Hi, this is a bit complicated but maybe someone can help here. I have an ASP.Net 2.0 page with a JavaScript file selector. I did this because I wanted to be able to select multiple files at a time. Here's a quick preview of the JS and ASP to show you what it looks like:

ASP
Code:
<td style="width:30%"><asp:FileUpload ID="fileBox" runat="server" />
                <asp:Button ID="grabFile" Text="Submit" runat="server" /></td>
            <td style="width:70%">
                <div id="files_list"></div></td>

JavaScript
Code:
function initFileUpload(){
    //Create an instance of the multiSelector class, pass it the output target and the max number of files
    var multi_selector = new MultiSelector( document.getElementById( 'files_list' ), 5 );
    //Pass in the file element
    multi_selector.addElement( document.getElementById( 'fileBox' ) );
}

...
...

/**
 * Add a new file input element
 */
this.addElement = function( element ){

...

// Add reference to this object
element.multi_selector = this;

// What to do when a file is selected
element.onchange = function(){
	if(!element.block)
	{
	element.block = true;
	// New file input
	var new_element = document.createElement( 'input' );
	new_element.type = 'file';
	// Add new element
	this.parentNode.insertBefore( new_element, this );
	// Apply 'update' to element
	this.multi_selector.addElement( new_element );

	// Update list
	this.multi_selector.addListRow( this );

...

/**
 * Add a new row to the list of files
 */
this.addListRow = function( element ){
// Row div
var new_row = document.createElement( 'div' );
// Delete button
var new_row_button = document.createElement( 'input' );
new_row_button.type = 'button';
new_row_button.value = 'Delete';
// References
new_row.element = element;


Now, what I would like to do is to get that list of elements (I can store it as an array in one variable if need be) in the VB codebehind on that button click. Is there a way to do that? When the button is clicked, I need to access that JS filelist/array and bring it into the VB codebehind.

Any help is apprecaited!
Thanks,
James
 
If I understand what you are trying to do, you will need to write your array list out to a hidden textbox within the form so that the array list is posted back when the submit button is clicked.

Then the VB code behind will have access to that textbox value. You can then convert it back to an array in the VB codebehind.



Pat B
 
Alright, I was wondering if that was going to be the solution. So, it's take values, paste to hidden textbox, and read into the code behind.

Thanks, I'll try that and let you know.
James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top