这个方法得到hidden input的值并返回,这样我们就得到了ID的前缀。第二个方法用来查询空间
function readValue(ctrlName)
{
var prefix = getCrtlPrefix();
var objCrtl = document.getElementById(prefix + ctrlName);
if (objCrtl) alert ( "Prefix: " + prefix + " - value: " + objCrtl.value);
else alert("not found!");
}
这个方法显示textbox控件的值。你会注意到,这里调用了getCtrlPrefix来计算textbox控件的ClientID。 我们可以增加一个按钮来调用这个方法:
<input type=button value="Read Value" onclick="javascript:readValue('mytext')">
这个html button会调用readValue。最后,把这个javascript的js文件加入aspx中。
<script language="JavaScript" src="mycontrol.js"></script>
运行这个页面,在text box中输入写数据,然后点击按钮,会出现一个消息对话框来显示ID前缀以及text box中的数据。
I this post I will try to explain the difference between those three commonly used properties. Each property is described in a separate section. Attached you can find a sample web site as well as two screenshots visually depicting the difference between the ID, ClientID and UniqueID properties. ID UniqueID For example if a Label with ID="Label1" is defined in a user control with ID = "UserControl1" the UniqueID of the Label will be "UserControl1$Label1". Adding another instance of the same user control (with ID = "UserControl2") will make the UniqueID of its child label to be "UserControl2$Label1". The UniqueID property is also used to provide value for the HTML "name" attribute of input fields (checkboxes, dropdown lists, and hidden fields). UniqueID also plays major role in postbacks. The UniqueID property of a server control, which supports postbacks, provides data for the __EVENTTARGET hidden field. The ASP.NET Runtime then uses the __EVENTTARGET field to find the control which triggered the postback and then calls its RaisePostBackEvent method. Here is some code which illustrates the idea: IPostBackEventHandler postBackInitiator = 推荐资讯
频道总排行
本频道月排行
评论排行
|