How can i achieve this in code behind

Last post 03-31-2009, 12:03 AM by cutechat. 4 replies.
Sort Posts: Previous Next
  •  03-27-2009, 12:56 PM 50372

    How can i achieve this in code behind

    Hello I would like the following javascript implemented in code behind the reason is I would like the submit to either upload or do something else depoending on some server validation
     

    <script type="text/javascript">

    function submitbutton_click()

    {

    var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');

    var uploadobj=document.getElementById('<%=Uploader1.ClientID %>');

    if(!window.filesuploaded)

    {

    if(uploadobj.getqueuecount()>0)

    {

    uploadobj.startupload();

    }

    else

    {

    var uploadedcount=parseInt(submitbutton.getAttribute("itemcount"))||0;

    if(uploadedcount>0)

    {

    return true;

    }

    alert("Please browse files for upload");

    }

    return false;

    }

    window.filesuploaded=false;

    return true;

    }

     
    <.Script>
     
    Thanks
  •  03-27-2009, 11:00 PM 50400 in reply to 50372

    Re: How can i achieve this in code behind

    Hi,
     
    You can use the Micosoft AJAX  , and handle the submit click event at server side , and then render script uploadobj.startupload(); to let the uploader start upload.
     
    Regards
    Terry
  •  03-28-2009, 6:54 PM 50415 in reply to 50400

    Re: How can i achieve this in code behind

    Would it be possible to provide a sample
    thanks
  •  03-30-2009, 12:45 PM 50452 in reply to 50415

    Re: How can i achieve this in code behind

    I keep getting an error object not supported I took out on the onclientclick event for the submit button and I am trying to upload by calling  the following function from code behind. I am using manual upload. When the user clicks on the submit button I would like to be able to know whether I have files in the queue, but I can't find a way to get this info from code behind
    Please advice
    Thanks

      Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    ScriptManager.RegisterStartupScript(Page, Type.GetType("System.String"), "Try Uploading", "StartUpload();", True)
     End Sub

    function StartUpload()

    {

     

    var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');

    var uploadobj=document.getElementById('<%=Uploader1.ClientID %>');

    //if(!window.filesuploaded)

     

    //{

     

     

    if(uploadobj.getqueuecount()>0)

    {

    uploadobj.startupload();

    }

    else

     

    {

    var uploadedcount=parseInt(submitbutton.getAttribute("itemcount"))||0;

    if(uploadedcount>0)

    {

    return true;

    }

    alert("Please browse files for upload");

    }

    // return false;

     

    //}

     

    // window.filesuploaded=false;

     

    // return true;

     

    }

     

  •  03-31-2009, 12:03 AM 50494 in reply to 50452

    Re: How can i achieve this in code behind

    Hi,
     
    You'd better setTimeout to check whether the uploader is initialized after AJAX postback.
     
    for example:
     

    function StartUpload()
    {
    var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');
    var uploadobj=document.getElementById('<%=Uploader1.ClientID %>');
    if(!uploadobj.startupload)//not initilaized
    {
     setTimeout(StartUpload,10);
     return;
    }

    ...other code.

    }

     
    Regards,
    Terry
View as RSS news feed in XML