1

I am trying to invoke a jquery function when a client press the image button, below is the code:

<asp:ImageButton ID="startUploadLink" runat="server" 
    onclick="startUploadLink_Click" />

    $("#startUploadLink").click(function () {
         $('#<%=FileUpload1.ClientID%>').uploadifyUpload();


         return false;
     });

want to invoke the above function when a user click on image button , also want some code behind logic of onclick image button should work in conjuction with the jquery function, is there any way of achieving it. Any help or suggestions will be highly appreciated.

2 Answers 2

1

Why not just use jQuery to bind the click event? You are already sort of doing that, but probably it doesn't work because you aren't looking for the client ID. I'm not sure why you did the right thing for finding FileUpload1 but not for binding the click event, but this should be all you need to do:

<asp:ImageButton ID="startUploadLink" runat="server" 
    onclick="startUploadLink_Click" />
    $('#<%=startUploadLink.ClientID %>').click(function () {
         $('#<%=FileUpload1.ClientID%>').uploadifyUpload();
 return false;
     });

jQuery bindings will override onclientclick but there's not much reason why you should use both. It's better to just use jQuery for binding events if you're already using it. They will work fine with codebehind/postbacks as well. If you want to PREVENT the form from posting from a jQuery bound event, then use e.preventDefault() in the javascript, otherwise, the default action (e.g. the ASP.NET postback function called from href) will occur.

Sign up to request clarification or add additional context in comments.

1 Comment

i will try this nd let u know if it works , thnx for taking time and looking into this issue
1

Try using onclientclick on the imagebutton

<asp:ImageButton ID="startUploadLink" runat="server"      onclientclick="startUploadLink_Click" />

2 Comments

can i use both onclientclick and onclick at a time , coz i want to trigger code behind method also .
@muhammad you can use both, remember to return true from your onclientclick function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.