【问题标题】:Problem with Profiles in ASP .NETASP .NET 中的配置文件问题
【发布时间】:2011-08-02 22:40:22
【问题描述】:

我制作了一个使用 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();
    }
}

【问题讨论】:

  • 您是说仅通过访问 pr.UserAddress 来阻止 BtnAdd_Click 中的保存,还是您是说如果您尝试更改页面加载中的地址然后调用 pr.Save,它不会保存?
  • 我认为他的意思是如果他从Page_Load 中取出代码,他就可以设置它。使用Page_Load 中的代码,他不能 - 因此我的答案 - 需要Page_Load 中的if !IsPostBack 测试,因为它在保存操作发生之前重置文本框文本...

标签: c# asp.net asp.net-membership


【解决方案1】:

您需要在 Page_Load 中添加一个 If !IsPostback,并在 if 中使用您当前的逻辑。

不要忘记,当您按下按钮时,Page_Load 将在 BtnAdd_Click 之前触发

【讨论】:

    猜你喜欢
    • 2011-11-29
    • 1970-01-01
    • 1970-01-01
    • 2013-06-30
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    • 1970-01-01
    • 2011-06-09
    相关资源
    最近更新 更多