Reputation: 1252
I am working on an old ASP.NET WebForms application that has an .aspx page with the following control:
<asp:Button ID="Budget_Approve" OnClick="Budget_Approve_Click" runat="server"
Visible="True" Width="100" Height="30" Text="Approve"></asp:Button>
The Budget_Approve_Click
event handler is never being hit, and I am trying to determine why. I noticed when the page loads, this code gets executed to add some inline js to the onclick
attribute:
Budget_Approve.Attributes.Add("onclick", "return confirm_approve();");
The HTML that gets rendered:
<input type="submit" name="ctl00$mainContent$Budget_Approve" value="Approve"
onclick="return confirm_approve();WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions("ctl00$mainContent$Budget_Approve",
"", true, "", "", false, false))"
id="ctl00_mainContent_Budget_Approve" style="height:30px;width:100px;">
So when I click, I expect confirm_approve()
to be executed. If it returns true
, I expect a postback and for my event handler to fire. Debugging in Chrome, I find that confirm_approve()
does indeed return true
:
However, the postback never happens, and the Budget_Approve_Click
event handler never gets hit. Why not?
Edit: I tried removing the line that adds the inline javascript code entirely. However, still no postback. The following HTML is rendered for the button:
<input type="submit" name="ctl00$mainContent$Budget_Approve"
value="Approve"
onclick="javascript:WebForm_DoPostBackWithOptions(new
WebForm_PostBackOptions("ctl00$mainContent$Budget_Approve",
"", true, "", "", false, false))"
id="ctl00_mainContent_Budget_Approve" style="height:30px;width:100px;" />
Update: Discovered that the postback does work in IE, but still not Chrome. Are there any browser-specific settings or issues that could potentially cause this problem?
Upvotes: 5
Views: 2834
Reputation: 2318
Check if your button is disabled somehow.
$("input[type='submit']").attr("disabled", "disabled");
If something like this happens, Chrome will have an incomplete POST request. ASP.NET will not fire the server side events.
Upvotes: -1
Reputation: 7430
Try this...
Budget_Approve.Attributes.Add("onclick", "if (!confirm_approve()) return false;");
Upvotes: 1
Reputation: 83358
I would just work around it with this:
Budget_Approve.Attributes.Add("onclick", "if (!confirm_approve()) return false;");
Upvotes: 3