日期:2014-05-18  浏览次数:20509 次

asp.net2.0中 原代码是<input id="giftcenthidden" type="hidden" value="0" runat="server"/>  生成后ID号会变的问题
原代码是 <input   id= "giftcenthidden "     type= "hidden "   value= "0 "   runat= "server "/>    生成后ID号会变

问题我有javascript要去调用这个id
有什么办法每个不同的服务器他变的id都不一样

------解决方案--------------------
// js in .aspx
var fld = document.getElementById( ' <% =giftcenthidden.ClientID %> ');
alert(fld.value);
------解决方案--------------------
这个和服务器没有关系,如果是user control,需要使用 client id
------解决方案--------------------
document.getElementById( " <% =giftcenthidden.ClientID %> ").value
------解决方案--------------------
具有 runat = server 的服务器控件, 其 id 非客户端可用 id,

其 ClientID 和 UniqueID 分别与客户端的 id 和 name 属性对应,

此 xxxID 为只读,由 asp.net 根据控件层次自动维护,