I have a button that looks like this with both OnClick and OnClientClick events
<asp:Button ID="btnExecute" CssClass="btn btn-primary" runat="server" Text="Execute" OnClientClick="setHiddenValues();" OnClick="Execute_Click" />
<script type="text/javascript">
function setHiddenValues() {
//set some values
}
</script>
EDIT: the code behind looks like this.
protected void Execute_Click(object sender, EventArgs e)
{
//execute some code
Response.Redirect("LandingPage");
}
Now when I click on the 'Execute' button, it only seems to go to the javascript and doesn't hit break points in the backend. It just redirects me to an empty page. There are no errors in js console of the browser's dev tools and also no errors being thrown in the backend. Network tab in the dev tools shows a 200 but I know the back end is not hit. What am I doing wrong here?
CodePudding user response:
try:
<asp:Button ID="btnExecute" CssClass="btn btn-primary"
runat="server" Text="Execute"
OnClientClick="setHiddenValues();return true;" OnClick="Execute_Click" />
On client click has to return a value of true, else the Onclick will not trigger.
CodePudding user response:
Try configure this in Page element:
<%@Page AutoEventWireup="true" EnableEventValidation="false" %>
