Disable postback at click on a button

后端 未结 10 557
名媛妹妹
名媛妹妹 2021-01-03 20:31

I want do disable postback after clicking a . I\'ve tried to do that by assigning onclick=\"return false\", but in the button doe

10条回答
  •  孤街浪徒
    2021-01-03 21:25

    Since you want to do it after the postback, I presume you want to prevent double click postbacks? In this case you are best off having some sort of state maintaining variable that you set after the first click on the client side. As a simple example

    var clicked = false;
    function AllowOneClick(){
       if(!clicked){
          clicked = true;
          return true;
        }
     return false;
     }
    

    You then set OnClientClick to return this method result on your button so OnclientClick="return AllowOneClick()" This will of course only work for one button, but it should give you the general idea.

提交回复
热议问题