asp.net控件开发基础(11)

  刚开篇的时后在最后把属性值用视图状态来保存时,得以把当前状态保存下来,关于视图状态的概述,这里不再累赘,没了解过的朋友可以在MSDN里输入视图状态概述了解一下.以下我们还是以以前讲过的内容为例,一起继续来改善控件的使用(第五篇和第九篇的例子)

  示例一

  我们启用了跟踪,按下确定按钮后,控件属性发生变化,按下无事件按钮后,控件状态则恢复到之前的状态,而且在跟踪状态下发现Custom无视图状态.

<%@ Page Language="C#" Trace="true" %>
<%@ Register Assembly="CustomComponents" Namespace="CustomComponents" TagPrefix="custom" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Custom1.Age
= 21;
Custom1.CustomMetier
= Metier.教师;
Custom1.CustomAddress.City
= "杭州";
Custom1.CustomAddress.State
= "中国";
Custom1.CustomAddress.Street
= "街道";
Custom1.CustomAddress.Zip
= "310000";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<custom:Custom ID="Custom1" runat="server">
</custom:Custom>
<br />
<br />
<ASP:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="确定" />
&nbsp; &nbsp;&nbsp;
<ASP:Button ID="Button2" runat="server" Text="无事件" />&nbsp;
</div>
</form>
</body>
</html>

NET技术asp.net控件开发基础(11),转载需保留来源!

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。