DevExpress Asp.net(9) ASPxHiddenField的特性与基本使用
2009-07-25 10:02
766 查看
1.1 说明
类似于HTML的Hidden标签,在页面上不可见,主要是用来传递和同步客户端与服务器端的数据,但HiddenField功能更强大,同时改进了Asp.net下的Hidden从客户端赋值 而服务器端取不到值的问题。三它继承了
IDictionary<String, Object>,
ICollection<KeyValuePair<String, Object>>,
IEnumerable<KeyValuePair<String, Object>>一系列的接口,除了可以用键/值对的方式存取数据外,还提供了一系列的操作方法,如:Add、Set、Get、Clear、Remove等方法进行操作。
1.2 代码及用法(Js方法原型同样适用)
public void Add(string propertyName, object propertyValue);
public void Set(string propertyName, object propertyValue);
public void Get(string propertyName);
public void Clear();
public bool Remove(string propertyName);
propertyName:key值。
propertyValue:Object.
1.3 代码与演示说明
HTML:在页在中放置一个ASPxHiddenField,并添加四个按钮进行读写操作控制。
JS代码,进行读写操作。
Add方法:用来向ASPxHiddenField写入值。
Remove方法:移除指定Key的值。
Get方法:获取指定Key的值
Clear方法:清除所有的值。
服务器代码,在加载页面时添加一个测试值。
类似于HTML的Hidden标签,在页面上不可见,主要是用来传递和同步客户端与服务器端的数据,但HiddenField功能更强大,同时改进了Asp.net下的Hidden从客户端赋值 而服务器端取不到值的问题。三它继承了
IDictionary<String, Object>,
ICollection<KeyValuePair<String, Object>>,
IEnumerable<KeyValuePair<String, Object>>一系列的接口,除了可以用键/值对的方式存取数据外,还提供了一系列的操作方法,如:Add、Set、Get、Clear、Remove等方法进行操作。
1.2 代码及用法(Js方法原型同样适用)
public void Add(string propertyName, object propertyValue);
public void Set(string propertyName, object propertyValue);
public void Get(string propertyName);
public void Clear();
public bool Remove(string propertyName);
propertyName:key值。
propertyValue:Object.
1.3 代码与演示说明
HTML:在页在中放置一个ASPxHiddenField,并添加四个按钮进行读写操作控制。
<dxhf:ASPxHiddenField ID="hdCollection" runat="server" ClientInstanceName="hdCollection"> </dxhf:ASPxHiddenField> <br /> Key: <input id="txtKey" type="text" /><br /> Value:<input id="txtValue" type="text" /> <br /> <input id="Button1" type="button" value="Add/Set" onclick="Add()" /> <input id="Button2" type="button" value="Get" onclick="Get()"/> <input id="Button3" type="button" value="Clear" onclick="Clear()" /> <input id="Button4" type="button" value="Remove" onclick="Remove()" />
JS代码,进行读写操作。
Add方法:用来向ASPxHiddenField写入值。
Remove方法:移除指定Key的值。
Get方法:获取指定Key的值
Clear方法:清除所有的值。
<mce:script type="text/javascript"><!-- function GetControl(id) { return document.getElementById(id); } function Add() { var key = GetControl("txtKey").value; var value = GetControl("txtValue").value; if (hdCollection.Get(key) == null) { hdCollection.Add(key, value); } else { hdCollection.Set(key, value); } } function Remove() { var key = GetControl("txtKey").value; if (hdCollection.Get(key) != null) { hdCollection.Remove(key); } else { alert(key + " 值不存在!"); } } function Get() { var key = GetControl("txtKey").value; if (hdCollection.Get(key) != null) { alert(hdCollection.Get(key)); } else { alert(key + " 值不存在!"); } } function Clear() { hdCollection.Clear(); } // --></mce:script>
服务器代码,在加载页面时添加一个测试值。
if (!IsPostBack) hdCollection.Add("DEMOKey", "Hello,World!");
相关文章推荐
- DevExpress Asp.net(9) ASPxHiddenField的特性与基本使用
- DevExpress Asp.net(7) ASPxTreeList的基本使用之一
- DevExpress Asp.net ASPxTreeList的基本使用之一
- DevExpress Asp.net(4) ASPxCallbackPanel的基本使用
- DevExpress Asp.net(8) ASPxTreeList的基本使用之二
- DevExpress Asp.net(4) ASPxCallbackPanel的基本使用
- DevExpress Asp.net(6) ASPxLoadingPanel的基本使用
- DevExpress Asp.net(5) ASPxCloudControl的基本使用
- DevExpress Asp.net(5) ASPxCloudControl的基本使用
- DevExpress Asp.net(1) ASPxButton的基本使用
- DevExpress Asp.net ASPxTreeList的基本使用之一
- DevExpress Asp.net(6) ASPxLoadingPanel的基本使用
- DevExpress Asp.net(7) ASPxTreeList的基本使用之一
- DevExpress ASP.NET 使用经验谈(8)-ASPxGridView自定义列和基本事件
- DevExpress ASP.NET 使用经验谈(7)-ASPxTreeList控件使用
- DevExpress ASP.NET ASPxGridView使用方法大全
- DevExpress ASP.NET 使用经验谈(5)-通过ASPxGridView实现CRUD操作
- DevExpress ASP.NET 使用经验谈(5)-通过ASPxGridView实现CRUD操作
- DevExpress ASP.NET 使用经验谈(6)-ASPxGridView属性设置与CRUD界面优化
- DevExpress ASP.NET 使用经验谈(1)-XPO模型的创建