473,427 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,427 software developers and data experts.

server control id's

Hi,

Merry Christmas to you all.

I have a problem with server controls, i am writing a C# ASP.NET web project
and i am creating custom server controls for some of the more common
element. One example is a NavigationMenu control or a Login control.

The problem is that when the page renders, say, the Login control, the ID of
the username field is changed from

id="username"

to

id="Login_ctl0__username"

or somthing like that...lol

Now, i have a generic javascript function

document.getElementById(username.ID).focus();

which sets focus to the specified control id and while the control is
rendered this javascript is added to the page using
Page.RenderStartupScript("focusScript", script).

This causes a javascript error because username.ID="username" when the page
is being rendered but by the time the script executes the username controls
id has changed to Login_ctl0__username.

Is there a way that i can prevent this from happening or a way that i can
get the correct id at the time my control is rendered.

Sorry about the length of this post, and hope someone can help.

Merry Christmas
Neil
Nov 19 '05 #1
4 1688
On the server, there is a property called Control.ClientID. This allows the
server to know what ID will be given to the controls. You can use this to
dynamically generate the code that will be sent to the browser.

"Neil Stevens" <ne**********@blueyonder.co.uk> wrote in message
news:eK**************@tk2msftngp13.phx.gbl...
Hi,

Merry Christmas to you all.

I have a problem with server controls, i am writing a C# ASP.NET web project and i am creating custom server controls for some of the more common
element. One example is a NavigationMenu control or a Login control.

The problem is that when the page renders, say, the Login control, the ID of the username field is changed from

id="username"

to

id="Login_ctl0__username"

or somthing like that...lol

Now, i have a generic javascript function

document.getElementById(username.ID).focus();

which sets focus to the specified control id and while the control is
rendered this javascript is added to the page using
Page.RenderStartupScript("focusScript", script).

This causes a javascript error because username.ID="username" when the page is being rendered but by the time the script executes the username controls id has changed to Login_ctl0__username.

Is there a way that i can prevent this from happening or a way that i can
get the correct id at the time my control is rendered.

Sorry about the length of this post, and hope someone can help.

Merry Christmas
Neil

Nov 19 '05 #2
Thats still not right, I tried the ClientID, UniqueID and ID properties and
they all report a value of "username" for the username text box, but when
the page is rendered into the browser the id property is changed to
"__ctl0_username".

I write the javascript using the ClientID property but this fails because
the id that is rendered is different to the id that i set in the javascript.

Where does the __ctl0_ part come from?

Thanks in advance
Neil

Have a prosperous new year

"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:uo**************@TK2MSFTNGP15.phx.gbl...
On the server, there is a property called Control.ClientID. This allows
the
server to know what ID will be given to the controls. You can use this to
dynamically generate the code that will be sent to the browser.

"Neil Stevens" <ne**********@blueyonder.co.uk> wrote in message
news:eK**************@tk2msftngp13.phx.gbl...
Hi,

Merry Christmas to you all.

I have a problem with server controls, i am writing a C# ASP.NET web

project
and i am creating custom server controls for some of the more common
element. One example is a NavigationMenu control or a Login control.

The problem is that when the page renders, say, the Login control, the ID

of
the username field is changed from

id="username"

to

id="Login_ctl0__username"

or somthing like that...lol

Now, i have a generic javascript function

document.getElementById(username.ID).focus();

which sets focus to the specified control id and while the control is
rendered this javascript is added to the page using
Page.RenderStartupScript("focusScript", script).

This causes a javascript error because username.ID="username" when the

page
is being rendered but by the time the script executes the username

controls
id has changed to Login_ctl0__username.

Is there a way that i can prevent this from happening or a way that i can
get the correct id at the time my control is rendered.

Sorry about the length of this post, and hope someone can help.

Merry Christmas
Neil


Nov 19 '05 #3
When are you trying to determine the ClientID? The Login__ctl0_ is being
appended to your control because it appears you are placing your control
inside another control that implements the INamingContainer. This is a
marker interface that will guarantee unique names as they are rendered to
the page.

You need to ensure you have added your control "username" to your containing
control (Placeholder?) and the page before trying to access the .ClientID
property.

bill
"Neil Stevens" <ne**********@blueyonder.co.uk> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Thats still not right, I tried the ClientID, UniqueID and ID properties and they all report a value of "username" for the username text box, but when
the page is rendered into the browser the id property is changed to
"__ctl0_username".

I write the javascript using the ClientID property but this fails because
the id that is rendered is different to the id that i set in the javascript.
Where does the __ctl0_ part come from?

Thanks in advance
Neil

Have a prosperous new year

"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:uo**************@TK2MSFTNGP15.phx.gbl...
On the server, there is a property called Control.ClientID. This allows
the
server to know what ID will be given to the controls. You can use this to dynamically generate the code that will be sent to the browser.

"Neil Stevens" <ne**********@blueyonder.co.uk> wrote in message
news:eK**************@tk2msftngp13.phx.gbl...
Hi,

Merry Christmas to you all.

I have a problem with server controls, i am writing a C# ASP.NET web

project
and i am creating custom server controls for some of the more common
element. One example is a NavigationMenu control or a Login control.

The problem is that when the page renders, say, the Login control, the ID
of
the username field is changed from

id="username"

to

id="Login_ctl0__username"

or somthing like that...lol

Now, i have a generic javascript function

document.getElementById(username.ID).focus();

which sets focus to the specified control id and while the control is
rendered this javascript is added to the page using
Page.RenderStartupScript("focusScript", script).

This causes a javascript error because username.ID="username" when the

page
is being rendered but by the time the script executes the username

controls
id has changed to Login_ctl0__username.

Is there a way that i can prevent this from happening or a way that i

can get the correct id at the time my control is rendered.

Sorry about the length of this post, and hope someone can help.

Merry Christmas
Neil



Nov 19 '05 #4
Like in a datagrid , if you are defining column and placing a
textbox(runat=server) with name txt within it in a <TemplateColumn
HeaderText="Column1">
<asp:TextBox id='txt' runat=server ></TextBox>
</TemplateColumn>
then while rendering the control name is changed to grid$_ctl1.. something
like that.

All this is done to make every server control id unique, as ASP.NET every
control is distinguished by the ID only....

"Neil Stevens" <ne**********@blueyonder.co.uk> wrote in message
news:#a**************@TK2MSFTNGP11.phx.gbl...
Thats still not right, I tried the ClientID, UniqueID and ID properties and they all report a value of "username" for the username text box, but when
the page is rendered into the browser the id property is changed to
"__ctl0_username".

I write the javascript using the ClientID property but this fails because
the id that is rendered is different to the id that i set in the javascript.
Where does the __ctl0_ part come from?

Thanks in advance
Neil

Have a prosperous new year

"Peter Rilling" <pe***@nospam.rilling.net> wrote in message
news:uo**************@TK2MSFTNGP15.phx.gbl...
On the server, there is a property called Control.ClientID. This allows
the
server to know what ID will be given to the controls. You can use this to dynamically generate the code that will be sent to the browser.

"Neil Stevens" <ne**********@blueyonder.co.uk> wrote in message
news:eK**************@tk2msftngp13.phx.gbl...
Hi,

Merry Christmas to you all.

I have a problem with server controls, i am writing a C# ASP.NET web

project
and i am creating custom server controls for some of the more common
element. One example is a NavigationMenu control or a Login control.

The problem is that when the page renders, say, the Login control, the ID
of
the username field is changed from

id="username"

to

id="Login_ctl0__username"

or somthing like that...lol

Now, i have a generic javascript function

document.getElementById(username.ID).focus();

which sets focus to the specified control id and while the control is
rendered this javascript is added to the page using
Page.RenderStartupScript("focusScript", script).

This causes a javascript error because username.ID="username" when the

page
is being rendered but by the time the script executes the username

controls
id has changed to Login_ctl0__username.

Is there a way that i can prevent this from happening or a way that i

can get the correct id at the time my control is rendered.

Sorry about the length of this post, and hope someone can help.

Merry Christmas
Neil



Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank,...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
3
by: Reetu | last post by:
Hi All, I have an html button on .aspx page. <INPUT class="sbttn" id="btnComplete0" onclick="onComplete ()" type="button" value="Mark Completed" name="btnComplete0"> When the user clicks...
11
by: Tom | last post by:
Hi all, I posted the same question one week ago in http://communities.microsoft.com/newsgroups/previewFrame.as p? ICP=msdn&sLCID=us&sgroupURL=microsoft.public.dotnet.framewo...
4
by: clintonG | last post by:
Technically speaking, this issue is not about modifying the HTML generated by server controls but preceding the HTML generated by server controls with an HTML control generated on the basis of the...
22
by: Mr Newbie | last post by:
I was thinking about developing a workflow application yesterday and was musing over the different approaches than one could take in restricting specific actions on a ticket( Form ) at any said...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
4
by: TS | last post by:
Steven, i lost this message conversation from outlook express and made a post online (see last one on this page). Please answer it as it hasn't been yet. thanks The clientID of our controls...
1
by: Andrew Jocelyn | last post by:
Hi I have a Formview control in a UserControl. The server-side validation is not working, i.e. the events are not firing when a button control which causes validation is fired or even when...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.