How to avoid Page_Load() on button click?

后端 未结 6 1723
鱼传尺愫
鱼传尺愫 2021-01-18 03:01

I have two buttons, preview and Save. With help of preview button user can view the data based on the format and then can save.

But when preview is clicked, one text

6条回答
  •  被撕碎了的回忆
    2021-01-18 03:43

    Use Page.IsPostback() in your aspx code (server-side). Like this:

    private void Page_Load()
    {
        if (!IsPostBack)
        {
            // the code that only needs to run once goes here
        }
    }
    

    This code will only run the first time the page is loaded and avoids stepping on user-entered changes to the form.

提交回复
热议问题