control ids on rendered content pages

A

Abraham Luna

i am using master and content pages in asp.net 2.0

on the rendered content page the control id is:

ctl00$ctl00$cphMainContent$cphCustomers$tbName

i created javascript expecting the id to be tbName. example below

var strName = document.getElementById("tbName").value;

is there a setting or something on the page that will just render the normal
control id instead of ctl00$ctl00$cphMainContent$cphCustomers$tbName

thank you
 
A

Abraham Luna

correction on original post:
the id on the rendered content page is:

ctl00_ctl00_cphMainContent_cphCustomers_tbName

the one with the $ symbol was the name property

please help if you can
 
C

clintonG

There's no setting or such as you surmise and this issue has been giving me
a hard time too.

I'm not 100% certain but reading and understanding the control hierarchy as
expressed when using Trace gives clues.
For example, "ctl00_ctl00..." suggests nested MasterPages. Is this correct?

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
 
A

Abraham Luna

yes it is nested masterpages. there should be a setting to turn that feature
off, because good programmers wont need asp.net to create unique ids for
them. i shouldn't have to render the page just to find out what asp.net
decided to name my controlid and create javascript like this:

document.getElementById("ctl00_ctl00_cphMainContent_cphCustomers_tbName")

it just seems unnecessary

thank you for your answer though
 
C

clintonG

You don't understand the way compilers work yet. There has to be some way to
manage memory and using an id of some schema type is the way computers have
always functioned. That you can now see some of the internal processes is a
benefit if you learn to understand what you are looking at.

While it is possible to do so it is not advisable to reference controls
using the generated control id. Every time you add or remove controls in the
page the control tree will change.

If you explain what objective you hoped to achieve by referencing a control
using client-side script I may be able to suggest a more practical solution.

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top