سؤال

I have a form. On load it gets filled by Page_Load method with data. 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. 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:

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

    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top