开发者

Question about Client IDs

开发者 https://www.devze.com 2022-12-27 21:15 出处:网络
I have a user control that is emmitting javascript using the ClientId function. For example: Out &= \"ValidatorHookupControlID(\" & Quote & ddlMonth.ClientID & Quote & \"), docume

I have a user control that is emmitting javascript using the ClientId function. For example:

Out &= "ValidatorHookupControlID(" & Quote & ddlMonth.ClientID & Quote & "), document.all(" & Quote & CustomValidator1.ClientID & Quote & "));" & vbCrLf

It appears to me that the ClientID function DOES not return the ultimate ID that is sent to the browser. Instead, the ClientID function on开发者_JAVA百科ly appears to be aware of its current parent control, which in this case is a the User Control and so the ID that is returned is the ID "dtmPassportExpirationDate_ddlMonth"

When in fact the usercontrol is included in a master page and the ultimate ID that is used is:

"ctl00_phPageContent_dtmPassportExpirationDate_ddlMonth"

I may be nuts, but that's what it appears to be doing. I expect that the ClientID function would return the ultimate ID used in the HTML.

Am I missing something?


Make sure you're reading the ClientID at the right time in the page lifecycle.

If you read it on the PreRender event or afterward, you will get the full ID. Before that, you can manipulate the WebForms objects by dynamically adding controls, so ASP.NET can't know for sure what the hierarchy is.

If you need more control over ClientIDs, upgrade to ASP.NET 4.0, where you have MUCH more fine-grained control over what gets sent out to the browser with WebForms.

0

精彩评论

暂无评论...
验证码 换一张
取 消