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

前端 未结 3 1286
醉梦人生
醉梦人生 2020-12-28 19:48

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

3条回答
  •  孤独总比滥情好
    2020-12-28 20:04

    You could use the onsubmit event of your page's form. This happens before the form is submitted, and will allow you to stop submission of the form if you need by cancel bubbling. In case you need this, the last 2 lines in this example will cancel bubbling across browsers.

    The JavaScript above is just for example, however this is (in my opinion) the preferred way to do what you're looking for. It looks something like this (in the center of the screen):

    Loading...

    This will work for any element that raises a PostBack, so you don't have to manually call ShowLoading() on every button or form element you may have on your page. I would replace the contents of ShowLoading() with some real loading functionality and not just the example code I threw together.

提交回复
热议问题