asp.net 2.0, control ids and clientID

I

Ily

Hi

I have a simple master page and a simpel webform that uses this master
page

Inside the webform is a textbox, the id of the textbox is txt1.

Now on the client, I want to do some scripting using this textbox and
that means I need the id.

But the client id is something like ct00_ContentPlaceHolder1_txt1
Hmmm - not very friendly for a start not to mention its a bit long! Who
is the world would call a control that! (okay I called mine txt1 - but
at least thats obvious!)

My issue is -

1)This prefix will change according to the namingcontainer, has anybody
found an elegant way of working with the control on the client,
regardless of where the control resides. I mean I would like to say on
my client

var objTxt1=document.getElementById('txt1');

but I cant!

Whats the reccomended route to take here....
 
A

Axel Dahmen

Hi,

this naming is necessary when your TextBox resides within another ASP.NET control. Such control can be put anywhere within a site multiple times, always providing the same kind of TextBox. So there needs to be a facility to uniquely identify all these TextBoxes.

Try to add following code to your page in the CodeBehind:

ClientScript.RegisterClientScriptBlock(typeof(this),"txtBox"
,"<script ...>var objTxt1=document.getElementById('"+TextBox1.ClientID+"');</script>");

HTH,
Axel Dahmen
 

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,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top