that's how IDs work for controls in "naming containers", to avoid naming conflicts. There's the Control.ClientID and Control.UniqueID properties to help you get references without hard-coding them. You might try the code below code,
if the javascript is inside the user control:
document.getElementById("<%= PageNumber.ClientID %>").innerHTML = id;
__doPostBack("<%= PageClick.UniqueID %>", "");
If this javascript is in the page, you might need something like:
document.getElementById("<%= MyControl.FindControl("PageNumber").ClientID %>").innerHTML = id;
__doPostBack("<%= MyControl.FindControl("PageClick").UniqueID %>", "");
I don't know if a copy-and-paste is enough, as the exact code depends on your actual structure. Hope you get the picture anyway.
==== 在USERCONTROL中的写法
错误:document.getElementById('ImageButton1').src = "images/submit.gif" 。返回Null,usercontrol里的控件在最终页面中的iD已经变化
正确: document.getElementById('<%=ImageButton1.ClientID%>').src = "images/submit.gif"
ASP.NET 控件ID使用技巧
本文介绍了在ASP.NET中如何正确使用控件ID来避免命名冲突,特别是针对UserControl中的控件。通过动态获取控件ID的方式,可以确保JavaScript能够正确地引用这些控件。
101

被折叠的 条评论
为什么被折叠?



