【问题标题】:ASP.net Wizard Control triggering Page_Load()ASP.net 向导控件触发 Page_Load()
【发布时间】:2014-08-23 16:54:55
【问题描述】:

我正在编写一个页面来收集用户信息(姓名、地址、信用卡信息等)以进行结帐。该页面有一个 ASP.net 向导控件,并假定用户已登录到他们的网站用户帐户。 Page_Load() 包含以下代码:

        // Get the user
        MembershipUser user = Membership.GetUser(User.Identity.Name);
        // Get the user's profile
        ProfileCommon Profile = (ProfileCommon)ProfileCommon.Create(user.UserName);

        FirstName.Text = Profile.FirstName;
        LastName.Text = Profile.LastName;
        OrganizationName.Text = Profile.OrganizationName;
        Address1.Text = Profile.Address1;
        Address2.Text = Profile.Address2;
        City.Text = Profile.City;
        State.Text = Profile.State;
        ZipCode.Text = Profile.ZipCode;
        Country.Text = Profile.Country;
        Telephone.Text = Profile.Telephone;
        Fax.Text = Profile.Fax;
        Email.Text = user.Email;

这成功地将用户信息加载到向导的第一步。但是,如果用户更改任何文本框中的文本并单击“下一步”进入下一步,然后单击“上一步”返回到第一步,则页面会从 Page_Load() 重新加载用户信息。有什么好的方法可以防止这种行为并在这些文本框中保留更改的文本?

【问题讨论】:

  • 搞定了。谢谢。
  • 请标记我的答案,谢谢

标签: c# asp.net wizard


【解决方案1】:

检查 IsPostBack。这就是 Web 表单的工作方式。每次点击都会调用 Page_Load()

【讨论】:

    【解决方案2】:

    你在使用 ISpostback 吗? if (!IsPostBack) { //页面加载代码放在这里 }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      相关资源
      最近更新 更多