简体   繁体   中英

How can i get hidden control id in parent page in the user control page using javascript

How can i get hidden control id in parent page in the user control page using javascript. there is a hidden input control in the page. i want to assign value to this control in the user control page which is used in this page. its an ascx page control.

<input type="hidden" runat="server" name="isChanged" id="isChanged" value="0" />

Register like as below

isChanged.ClientID- is serverside property... so this will work for you 

document.getElementById("<%=isChanged.ClientID %>");

You could do this using jquery using the 'ends with' selector.

var element = $("input[id$=isChanged]")[0];

This assumes you only have one input on your page with an id which ends in 'isChanged'. The reason we use ends with is because asp will make the client side id of your control something like ct100$placeholder1$mypanel$isChanged.

A more robust solution would be to have a property on your usercontrol (eg 'ClientIdOfHiddenField') that you set from your parent page on page_load

protected void Page_Load(object sender, EventArgs e)
{
    UserControl1.ClientIdOfHiddenField = isChanged.ClientID;
}

then in the markup of your user control you can have

var element = document.getElementById("<%= ClientIdOfHiddenField %>");

If you are using jQuery you should be able to use

var hidden = $('input[id$="isChanged"]');

otherwise @Pranay Rana's answer should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM