I made an ASP .net application which use the asp .net login system. I use the a class which gets some details of the logged in user such as Name, address etc. In the page that the user can change his details i have those commands. If i don't use the commands in the page_load the address changes in the database successfully, but if i use them the database doesnt make the changes in the address. How is it possible? The profileC class uses the Inherits from ProfileBase class
protected void Page_Load(o开发者_开发百科bject sender, EventArgs e)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
classes.ProfileC pr = classes.ProfileC.GetProfileC(HttpContext.Current.User.Identity.Name);
TxtAddress.Text = pr.UserAddress;
}
}
protected void BtnAdd_Click(object sender, EventArgs e)
{
classes.ProfileC pr = classes.ProfileC.GetProfileC(HttpContext.Current.User.Identity.Name);
pr.UserAddress = TxtAddress.Text;
pr.Save();
}
}
You need an If !IsPostback
in your Page_Load
with your current logic inside the if
.
Don't forget when you press a button Page_Load
will fire before the BtnAdd_Click
精彩评论