Home All Groups Group Topic Archive Search About

JavaScript, ASP, and VB :)

Author
28 Sep 2006 3:46 PM
JimmyFo
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

<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

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;[/code]


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

Author
28 Sep 2006 4:42 PM
Cor Ligthert [MVP]
Jimmy,

There are 3 methods for you, in Net 2.0 you have even the upload method,
that I never used.

http://support.microsoft.com/kb/323245/EN-US/

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx

And with the old request.files("fileid")

I hope this helps,

Cor


Show quoteHide quote
"JimmyFo" <jimm***@gmail.com> schreef in bericht
news:1159458371.695986.310430@i42g2000cwa.googlegroups.com...
> 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
>
> <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
>
> 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;[/code]
>
>
> 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
>