RegisterHiddenField does not work inside .ascx components

F

Francis

Hi all,

I am writing a .cs component that sets RegisterHiddenField on the
server side and generates javascript to execute on the client side.

It works when the component is directly in the page, but not when it
is inside an ascx. In the source code of the page, I can see that the
ascx adds an prefix before the ID of the hidden field. This kind of
thing is no problem when you are using javascript on objects such as
buttons, that have a representation on the server side, so you can
write Button1.ClientId . But RegisterHiddenField does not rest on any
objects on the server side, so I don't see how I can find out what the
client ID is going to be.

Here is an exemple of registering on the server side:
this.Page.RegisterHiddenField("visibleElement", "0") ;

Here is an exemple of using on the client side side:
function showHide(str)
{
idOfElementToHide = document.getElementById(visibleElement).value;
document.getElementById(idOfElementToHide ).style.display= 'none';
....


Here is what I get in the source code when the component is used
directly in the page:

<input name="visibleElement" id="domainsToOpen" type="hidden" />

here is what I see when the component is used inside a .ascx
component:
<input name="TabControl1:_ctl1:visibleElement"
id="TabControl1__ctl1_visibleElement" type="hidden" />
 

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,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top