简体   繁体   English

页面在发送数据之前刷新表单

[英]Page refreshes the form before data is sent

I have a form. 我有一个表格。 On load it gets filled by Page_Load method with data. 加载时,将通过Page_Load方法将其填充数据。 Now if user changes data and clicks the submit button the page refreshes reloads the original data and then onClick metod of the button gets called. 现在,如果用户更改数据并单击“提交”按钮,页面刷新将重新加载原始数据,然后调用按钮的onClick方法。 Now it loads wrong (original) data from form not the data user put in. 现在,它从表单而不是用户输入的表单中加载错误的(原始)数据。

How do avoid this ? 如何避免这种情况? Thanks. 谢谢。

In the Page_Load you need to wrap the data loading code in if (!IsPostBack){} like below: 在Page_Load中,您需要将数据加载代码包装在if (!IsPostBack){}如下所示:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
       //Your code to load data

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM