Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a javascript function before postback of asp.net button

Tags:

asp.net

I have an asp.net button which is runat server, there is a function handle that postback of button onclick.

How can I display a "loading ..." word in the page before going to the server procedure?

like image 229
Jay Avatar asked Jun 30 '09 01:06

Jay


People also ask

How do you use PostBack in JavaScript?

How to Raise a Postback from JavaScript? To do this, we need to just call the __doPostBack() function from our javascript code. When the above function is called, it will raise a postback to server.

Does ASP NET do PostBack?

PostBack is the name given to the process of submitting an ASP.NET page to the server for processing. PostBack is done if certain credentials of the page are to be checked against some sources (such as verification of username and password using database).

Is post back in JavaScript?

postback=true) - you can then get the page url with window.


1 Answers

Hook up OnClientClick to some javascript function that returns true or false. The postback occurs if it returns true else it is canceled.

  <asp:Button id="MyButton" runat="Server" Text="Close" 
                       OnClientClick="return  PromptClose();"/>


  <script type="text/javascript">
   function PromptClose(){
       return prompt("Do you really want to close this window?");
   }
  </script>
like image 76
TheVillageIdiot Avatar answered Jan 04 '23 04:01

TheVillageIdiot