SlickUpload
Welcome Guest Search | Active Topics | Log In | Register

Button "Click" Event Not Firing Options
chrisajohn
#1 Posted : Monday, November 23, 2009 2:36:59 PM
Rank: Newbie

Groups: Registered

Joined: 11/10/2009
Posts: 8

I have a button (.NET 3.5) like so:

<asp:Button CssClass="app_button" ID="btnSave" Text="  Save &amp; release " OnClientClick="return startUpload();" runat="server" />

-------

The javascript looks like this (passing in the UploadConnector ClientID ("spuUploadBase" is a user control where I expose the uploadconnector's clientid):

        function startUpload()
        {
             if (valForm())
          {
                 kw.get("<%= spuUploadBase.UploadConnectorID %>").submit();
                 return true;
           }
           else
           {  
                 return false;
           }
        }

"valForm" is a javascript function that does various checks, raises alerts, if needbe, and returns true or false (false if validation failed, true if it succeeds).

---------

I am using the "Upload Connector" control in conjunction with the "Upload Progress Display", "FileSelector", and "FileList" controls as I need to have more than one file uploader on a page at a given time.  My UploadConnector looks like this:

<kw:UploadConnector ID="uploadConnector" runat="server" OnUploadComplete="up_UploadComplete" AutoUploadOnPostBack="false" />

--------

The button click code (in the vb code behind looks like so):

    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click

//Code taken out for bevity's sake.

    End Sub

--------

What I need to have happen is this:

  1. User clicks on "Save" button.
  2. The "ValForm" code is run.  If it returns false, alerting the user and preventing the postback from taking place.
  3. If the "valForm" code returns "true", then start the upload process and run the button click information.
What I am seeing is that when valForm (and in turn "startUpload" returns false), it works as expected.  However, when it passes the valForm test it starts the upload correctly, and performs a postback (I did some "Response.Write("got here") on the IsPostBack part of the Page_Load method to confirm), however it doesn't fire the button click event code.

A co-worker and I suspect that this may be happening because the page thinks the uploader is doing the postback but not the button.  Not sure if that's right or if you can point us in the right direction.

Thank you so much for your help.

 

 

 

Axosoft
#2 Posted : Monday, November 23, 2009 9:38:13 PM
Rank: Administration


Groups: Administrators

Joined: 7/7/2005
Posts: 1,586
Location: Scottsdale, AZ

Your suspicions are correct on the postback -- when you call submit() directly, only the UploadComplete event will be fired. There are a couple options to handle this scenario:

 - Instead of using AutoUploadOnPostBack="false", calling your validation logic, and then calling submit(), use an ASP.NET validator to run your validation. SlickUpload will call all ASP.NET validators before beginning an upload, and only upload if they are valid. 

 - Instead of using AutoUploadOnPostBack="false", calling your validation logic, and then calling submit(), use a form onsubmit handler to call your validation. Something like: <form ... onsubmit="return valForm();" />. SlickUpload will call the onsubmit handler before uploading, and only upload if it returns true.

 - Use your existing logic, but put the upload handling code in the UploadComplete event. Use the UploadedFile.FileSelectorId to determine which selector was used to select the file.

Let me know if one of these options will work for you. If not, we can explore some changes to allow you to pass in the id of the control specifically on the submit() call.

chrisajohn
#3 Posted : Tuesday, November 24, 2009 11:15:15 AM
Rank: Newbie

Groups: Registered

Joined: 11/10/2009
Posts: 8

Thanks!

We used the second suggestion and it worked great.

Thanks again!!

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.