INamingContainer

S

Sam Samnah

I'm having a hard time with INamingContainer.

I'm building a composite control that has a implements an HtmlGenericControl
Div control and an HtmlInputHidden control the Generic control works fine
but the HtmlInputHidden control is giving me all kinds of problems.

My code is something like this:

protected HtmlInputHidden HIH;
protected HtmlGenericControl HGC;

protectected overriden void CreateChildControls(){

Controls.Add(new LiteralControl("Bla Bla Not inportant static tags"));
HIH=new HtmlInputHidden();
HIH.Name=this.ClientID; // this produces the name something as follows
parentControl1:_ct14.
Control.Add(HIH);

<--Initialize the HtmlGenericControl bla bla left out for brevity-->

Now, my problem is this. I need to access HIH.name for a client-side
function (written in javascript) that access this control by its name as
apposed to the DOM document.getElementById(ID) something like
parentControl1_ct14.value. When I set the HIH.Name to the ClientID instead
of getting the expected parentControl1_ct14 I get parentControl:_ct14
(Notice the colon) This colon for some reason behaves like a delimiter in
javascript and returns an exception requiring a ")". I have also tried
using UniqueID but that too returns the same problem. Can someone tell me
what I am doing wrong here? this is driving me crazy and causing all kinds
of grief for me.

Thank you in advance,

Sam-
 
P

Paul Glavich [MVP ASP.NET]

The problem does not look related to INamingContainer. As you are probably
aware, its just a marker interface used so that when the controls are
rendered, the name takes on a heirarchical scheme and the container control
name is pre-pended to the ClientID to make it constant and unique.

If I understand the problem correctly, to access the HIH control, you should
reference its ClientID property value using your client side javascript.
This may require that you set this value using some server side registration
script (eg. setting the value of a hidden control, javascript variable etc.
from the server side) and then have your client side code, pick up that
ClientID, and use it to get a reference to the control you wish to
manipulate via 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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top