ASP .NET 中的配置文件问题
我制作了一个使用 asp .net 登录系统的 ASP .net 应用程序。我使用一个类来获取登录用户的一些详细信息,例如姓名、地址等。在用户可以更改其详细信息的页面中,我有这些命令。如果我不使用 page_load 中的命令,数据库中的地址会成功更改,但如果我使用它们,数据库不会对地址进行更改。怎么可能呢? profileC 类使用从 ProfileBase 类继承的
protected void Page_Load(object 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();
}
}
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(object 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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在
Page_Load
中使用If !IsPostback
,并在if
中包含当前逻辑。不要忘记,当您按下按钮时,
Page_Load
将在BtnAdd_Click
之前触发You need an
If !IsPostback
in yourPage_Load
with your current logic inside theif
.Don't forget when you press a button
Page_Load
will fire before theBtnAdd_Click