您的位置:首页 > 其它

为匿名用户实现简单的数据类型配置

2009-08-23 00:37 501 查看
首先配置web.config

<system.web>

<anonymousIdentification enabled="true"/>
<profile enabled="true">
<properties>
<add name="Name" allowAnonymous="true"/>
<add name="LastSubmit" type="System.DateTime" allowAnonymous="true"/>
<group name="Address">
<add name="City" allowAnonymous="true"/>
<add name="PostalCode" allowAnonymous="true"/>
</group>

</properties>
</profile>
</system.web>

<fieldset style="width: 300px;">
<legend >实现匿名用户个性化用户配置</legend>
<br />

<table class="style1">
<tr>
<td class="style2">
上次提交</td>
<td>
<asp:Label ID="labLastSubmit" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td class="style2">
用户姓名</td>
<td>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
所在国家</td>
<td>
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
邮政编码</td>
<td>
<asp:TextBox ID="txtPostalCode" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
 </td>
<td>
<asp:Button ID="btnSubmit" runat="server" onclick="btnSubmit_Click" Text="提交" />
</td>
</tr>
</table>

</fieldset>

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
DisplayProfileInfo();
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
//保存信息到Profile属性中
Profile.Name = txtName.Text;
Profile.Address.City = txtCity.Text;
Profile.Address.PostalCode = txtPostalCode.Text;
Profile.LastSubmit = DateTime.Now;
//显示用户配置信息
DisplayProfileInfo();
}
private void DisplayProfileInfo()
{
txtName.Text = Profile.Name;
txtCity.Text = Profile.Address.City;
txtPostalCode.Text = Profile.Address.PostalCode;
DateTime time = Profile.LastSubmit;
if (time.Year == 1)
{
labLastSubmit.Text = "空";
}
else
{
labLastSubmit.Text = time.ToString();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: