Access to a HiddenFiled in a Content control from javaScript

J

Javier Martinez

Hi
I have a page using a MasterPage, in my page I need to access a HiddenField1
control declared in the Control element from javascript. But which is the
hierachy?
The folowing code doesn't work:

Conten1.HiddenField1.value

The page is:
<asp:Content ID="Content1" ContentPlaceHolderID="bodyContentPlaceHolder"
Runat="Server">
<asp:HiddenField ID="HiddenField1" runat="server"/>
</asp:Content>


Before to use masterpages it was easy:
form1.HiddenField1.value

Thanks in advance
Javier
 
P

Paul Henderson

The use of master pages means that the elements have their names
mangled to ensure they are unique; the quick and nasty solution is just
to inspect the HTML code produced by ASP.NET and see what ID it has
given for the HiddenField, and then hard-code this into your
Javascript. The asp:content tags are not rendered into the HTML at all.

A nicer solution is to figure out what mangled ID has been assigned to
the control by using the server-side property ClientID, and then
somehow embed that into your Javascript.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top