0

Void button has a confirm box after receiving true, expecting running another button's click event however, Void2_Button_Click not run, where is wrong?

protected void Void2_Button_Click(object sender, EventArgs e)
{
        // do something    
}


Void_Button.Attributes.Add("onclick", "var agree=confirm('Confirm to void?'); if (agree){document.getElementById('Void2_Button').click();}");

This question has not been solved yet, Who can answer?

1
  • Why do you run another button's click event programatically? Isn't it better to have both buttons trigger the same event handler in code behind? Commented Mar 9, 2011 at 9:00

2 Answers 2

2

You can also have ordinary server side click for the first button, that will simply call the click event of the other button:

<asp:Button id="Void_Button" runat="server" Text="Void" OnClick="Void_Button_Click" OnClientClick="return confirm('Confirm to void?');" />

protected void Void_Button_Click(object sender, EventArgs e)
{
   Void2_Button_Click(sender, e)
}
Sign up to request clarification or add additional context in comments.

Comments

0

You would have to use the .ClientID for javascript. Try

Void_Button.Attributes.Add("onclick", "var agree=confirm('Confirm to void?'); if (agree){document.getElementById('"+Void2_Button.ClientID+"').click();}");

5 Comments

@Mathew are you adding this in Page_Load ?
yes, add in page load after if (!Page.IsPostBack), not trigger
if i do not do this, any other simple method to call function in asp .net cs code from javascript like above?
Can you try with out the if(!IsPostBack) condition in page_load?
tried, without !postback, not trigger, label not update and not server.transfer to another page, seems not run the 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.