天天看点

ASP.NET2.0 自定义CreateUserWizard

ASP.NET2.0 自定义CreateUserWizard

MSND原文如下:

下面的代码示例使用 CreatedUser 事件将用户姓名存储在个性化属性中。该代码示例需要 Web.config 文件中的下列项。

<configuration>

<system.web>

<profile>

<properties>

<add name="lastName" />

<add name="firstName" />

</properties>

</profile>

</system.web>

</configuration>

C#  复制代码
<%@ page language="C#"%>
            <script runat="server">
            void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
            {
            Profile.SetPropertyValue("UserName",firstName.Text + " " + lastName.Text);
            }
            </script>
            <html>
            <head runat="server">
            <title>
            CreateUserWizard.CreatedUser sample</title>
            </head>
            <body>
            <form id="form1" runat="server">
            <div>
            <asp:createuserwizard id="CreateUserWizard1" runat="server">
            <wizardsteps>
            <asp:wizardstep runat="server" steptype="Start" title="Identification">
            Tell us your name:<br />
            <table width="100%">
            <tr>
            <td>
            First name:</td>
            <td>
            <asp:textbox id="firstName" runat="server" /></td>
            </tr>
            <tr>
            <td>
            Last name:</td>
            <td>
            <asp:textbox id="lastName" runat="server" /></td>
            </tr>
            </table>
            </asp:wizardstep>
            <asp:createuserwizardstep runat="server" title="Sign Up for Your New Account">
            </asp:createuserwizardstep>
            </wizardsteps>
            </asp:createuserwizard>
            </div>
            </form>
            </body>
            </html>
                  

上面加入了一个自定义的wizardstep ,在界面上,可以如下操作:在CreateUserWizard控件上右击,在弹出的菜单上选择“ADD/REMOVE wizardstep”,在出出的界面上单击ADD就可以增加一个wizardstep,用上下箭头把新建的步骤置于中间。

发现按此做,会有些错误;

改正如下:

  1.配置文件中<add name="lastName" /> <add name="firstName" /> 与后面的Profile.SetPropertyValue("UserName",firstName.Text + " " + lastName.Text);  不一致。改正方法1是前者改为.<add name="UserName" />,或者后者改成:Profile.SetPropertyValue("firstName",firstName.Text);Profile.SetPropertyValue("lastName", lastName.Text); 

2.Profile.SetPropertyValue("UserName",firstName.Text + " " + lastName.Text);  后面添加语句Profile.Save(),否则不会保存。

3.配置文件中应允许匿名访问Profile:

<system.web>

      <anonymousIdentification        enabled="true"     />

    <profile >

      <properties >

       <add name="lastName" allowAnonymous="true"/>

        <add name="firstName" allowAnonymous="true"/>

      </properties>

    </profile></system.web>

4.代码应编写在完成注册的按钮下面:

       protected void CreateUserWizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)

    {

        Profile.SetPropertyValue("firstName", firstName.Text);

        Profile.SetPropertyValue("lastName", lastName.Text);

        Profile.Save();

    }

posted on 2007-05-22 22:14 麦子 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/maixf/archive/2007/05/22/756226.html

c#