ID & NaimgContainer

  • Thread starter Thread starter Lloyd Dupont
  • Start date Start date
L

Lloyd Dupont

I'm createing a NamingContainer (which could be nested deep in the
hierarchy)
Which contains an HtmlInputField
I then want to do some javascript on the (hidden) input field.

Problem is, I don't know how to get my InputField id :-/

So far I'm using hidden.ClientID but this returns me:
ctl01_BackgroundPicture
whereas the end result, in the web page,
is:ctl00_mainContent_BlogMonthList1_b_1_ctl01_BackgroundPicturewhat could I
do?
Thanks fo any tips!
 
From your description cant you just use this ?

var myHidden = document.getElementById("theIdOfTheHiddenElement")

myHidden.value = "Whatever I want to set this to"

?
 
let's make it clearer (hopefully)

My HTML looks like that:
<input type=hidden
id='ctl00_mainContent_BlogMonthList1_b_1_ctl01_BackgroundPicturewhat' />
<input type=button
onclick="document.getElementById('ctl01_BackgroundPicturewhat').Value='42';"/>

This doesn't work as, you could see, the element name in the function
getElementById is incomplete (there is only the end of the name).

the code for the user control which output this part of the page looks like
that:
class MyControl : Control
{
HiddenField myHidden;
LinkButton link;
protected override void CreateChildControls()
{
Controls.Add(myHidden = new HiddenField());

link = new LinkButton();
link.Text = "Don't Click Me!";
link.ClientClick =
string.Format("document.getElementById('{0}').Value='42'",
myHidden.ClientId);
Controls.Add(link);
}
}

Now, how could I pass the correct (final/complete) id in ClientClick?
 
I made it work with that additional code:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
link.ClientClick =
string.Format("document.getElementById('{0}').Value='42'",
myHidden.ClientId);
}
 

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

Back
Top