开发者

Not able to access dynamic controls (inside ascx) using javascript (on aspx page)

开发者 https://www.devze.com 2023-01-01 20:00 出处:网络
I have a user control (ascx) which contains a control (hidden field). In the page_load event of ascx, i have the below code:

I have a user control (ascx) which contains a control (hidden field). In the page_load event of ascx, i have the below code:

HyperLink.Attributes.Add("onclick", "JavaScript:return AccessControl('" + hdnField.UniqueID + "');"); Note: The hidden field resides in .ascx file.

I want to access this hidden field at runtime and i have the below javascript function in aspx page that loads the usercontrol.

func开发者_运维知识库tion AccessControl(hdnFieldId) { var ctrl = document.getElementById(hdnFieldId); alert(ctrl);

I am getting 'null' value in the alert. I tried using 'ClientID' and 'this' instead of 'UniqueId'. I am wondering why this is not working. I am using .net 2.0.


Does the hidden field exist when the page renders? Try moving the code for adding the control into the page init, this is the safest place to dynamically add controls to the page.

0

精彩评论

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

关注公众号