skip to Main Content

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?

3

Answers


  1. Chosen as BEST ANSWER

    It turns out my issue was much simpler. The 'Debug' option was not selected. The wiring was correct and it was hitting the backend but I was not able to hit the breakpoints in the backend because I was in Release mode.


  2. 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.

    Login or Signup to reply.
  3. Try configure this in Page element:

    <%@Page AutoEventWireup="true" EnableEventValidation="false" %>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search