0

I have two button as shown below:

1st Button:

<asp:Button ID="btn1" runat="server" Text="First Button" CausesValidation="False"
     UseSubmitBehavior="False" />

2nd Button:

 <button type="reset" id="btn2" runat="server">
        <span>Second Button</span>
 </button>

Now If I click btn1 I need to do some stuff and then I need to click btn2 automatically at the end of the process which needs to perform some client side operations.

This is what I need to do:

Protected Sub btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.Click
//Do some Stuff

//Here I need to make btn2 click automatically
End Sub

As my btn2 should do this:

$("#<%=btn2.ClientID%>").click(function () {
//perform some taks
}
1
  • So you want button one to submit the form and run your server side click event for it. Then after the page has loaded in the browser, you want it to run some code on the client to click button two? Commented Apr 19, 2012 at 20:56

3 Answers 3

1

This is not how Server side code works. When button 1 will click then 1) all the client side code will run 2) and then server side click button will be called.

Currently you have mixed up server side code. What you can do is :

  1. Perform the button 1 click code.

  2. Put the code on button 2 click in a separate function and call that function at the end of button 1 code.

What you are trying to do is, unfortunately, incorrect.

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

Comments

1

I think you used to be able to emit script dynamicly using ScriptManager. You could try that to emit client script in btn1_Click that will click btn2 on the client when the page loads in the browser.

I'm with Beenish though. Without any other context, this sounds like a bad idea. I would try and turn btn1_Click into a webmethod and call it from the client using jquery. You might check this question for calling a webmethod from jquery

Comments

0

It sounds like what you want is this:

$("#<%= btn1.ClientID %>").click(function(){

    //do some stuff

    $("#<%= btn2.ClientID %>").trigger("click");
});

Comments

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.