How to detect/track postback in javascript?

后端 未结 11 1359
猫巷女王i
猫巷女王i 2020-12-02 18:51

How to detect/track/check postback in javascript(e.g in asp.net Page.isPostBack())? Any suggestion?

11条回答
  •  一生所求
    2020-12-02 19:28

    If you want to check whether the current page will be a postback if the user clicks on a submit button, you can check for the presence of ViewState:

    
    

    You can use something like document.getElementById("__VIEWSTATE") or the jQuery equivalent.

    However, if you want to see whether the current page was generated in response to a postback, then you need to insert that data into the page on the server side first.

    For example:

    function isPostBack() {
      return <%= Page.IsPostBack %>;
    }
    

提交回复
热议问题