Does the OnClick button not start the first click in ASP.NET?

protected void ButtonCancel_Click(object sender, EventArgs e) { Response.Redirect("~/Logon.aspx"); } 

Does this not work the first time you click the cancel button?

+2
source share
4 answers

Make sure you bind to the event only if IsPostBack is true . Otherwise, we will not know without a code.

+1
source

Are you sure the markup is correct?

Is it difficult to look like this?

 <asp:Button ID="ButtonCancel" OnClick="ButtonCancel_Click" /> 

To do this, you need the "OnClick" attribute.

+1
source

Do you really need to send back to go to another page? You can simply call javascript to do this:

 <input ID="btnCancel" type="button" value="Cancel" onclick="javascript:window.location='/logon.aspx';" /> 
0
source
 <asp:Button ID="Button1" runat="server" Text="save" OnClientClick="return confirmmation()" onclick="Button1_Click" /> <script type="text/javascript"> function confirmmation() { return confirm('confirm'); } </script> <asp:Button ID="Button2" runat="server" Text="cancel" CausesValidation="False" onclick="Button2_Click" /> 

On your refrence, I tried the same thing and it worked. The button has a reverse gear. Can I see your button_save_click event code and page load code.

0
source

Source: https://habr.com/ru/post/1341589/


All Articles