Renaming of controls in Asp.Net 2

C

C. Levasseur

I would like to use client side scripting for enabling/disabling buttons
(depending on values in other fields). This worked fine in Asp.Net 1.1 but
in Asp.Net 2.0, all the names and the id's of the web and html controls are
modified, for example:

<asp:Button Runat="server" ID="modifyCtrl" Text="Modify" /asp:Button> is
generated as
<input type="submit" name="ctl00$main$modifyCtrl" value="Modify"
id="ctl00_main_modifyCtrl" />

How can my client side scripts disable my button if Asp.Net 2.0 modifies the
ID's and the names? Is there a method I can call that will convert my client
scripts so they won't break if Asp.Net changes the naming convention in a
future version (such as RegisterClientScriptBlock() )?

C.Levasseur
 
C

clintonG

Did somebody break your version of JavaScript so getElementById( ) stopped
working?
Did they remove the split( ) function or something? Not include support for
arrays?

Try it out. The name of your control will be in the array after you split
the results returned by getElementById. Don't hard-code any references to
any value assigned to the control tree as any change to your page will
result in a differently ordered control tree and in fact any changes to any
controls at run-time can and will remove them from the tree which remains
adressable on both the client and the server. If your client-side script is
designed well your code should live to a ripe old age. Well, at least until
3.0 is released :)

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

C. Levasseur

But my problem is on the client side... GetElementById() is on the server
side.
Sure, I could probably use split ou RegEx stuff to find the control in my
page using javascript but that sure makes an ugly script just to disable a
button. ASP.Net 1.1 didn't change the values of the controls it generated on
the server side so it was easy to make a client side script to disable a
control. ASP.Net 2.0 is supposed to make everybodies life easier so I
thought that there must be a way to either generate a control with a named
that is not mangled by asp.net 2.0 or that there must be a easy way to find
the name of the mangled control ID in the script. I could also modify my
script so that it looks for the control ID "ctl00_main_modifyCtrl" but I
don't want my code to break if MS changes the name mangling convention in a
future version.


C.Levasseur

<asp:Button Runat="server" ID="modifyCtrl" Text="Modify" /asp:Button>
is generated as
<input type="submit" name="ctl00$main$modifyCtrl" value="Modify"
id="ctl00_main_modifyCtrl" />
 
C

clintonG

But you're wrong about getElementById and you don't even write it correctly
so how could you know what you're talking about? I can help explain what I
know but I can't win an argument with someone who continues to argue the
facts just to argue about something.

Its a good thing though that your complaint will actually force you to learn
how and why you are misinformed as you're only other choice is to continue
trying to develop software misunderstanding what you think you are doing.

Finally, the .NET Framework manages the code and memory required to compile
and run the code. Right? You can think of it as your house or wherever you
live. If it didn't have an address the mail could not be delivered to the
right person. The control tree is the same analogy. Each control is a house
or an apartment and needs an adressing and identification schema so the mail
can be delivered to the right class.

That control tree was present in 1.1 but you do not understand how compilers
work. The 2.0 release is even more developer friendly and lets us see and
access more. You just need to learn how to think and see what it is. Go buy
some glasses :)

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

C. Levasseur

Sorry, my posting was not ment to upset you. I realy don't want to argue
with you as I need help to understand...
Ok, so you are right, getElementById() is client side javascript. So lets
say my aspx file has the following code in it:

<asp:Button Runat="server" ID="modifyCtrl" Text="Modify" /asp:Button>

asp.net 2.0 generates the following code on the client side:

<input type="submit" name="ctl00$main$modifyCtrl" value="Modify"
id="ctl00_main_modifyCtrl" />

If I understand what you are saying, I could use
document.getElementById("modifyCtrl") in my client side script. to get
access to my control. But, in asp.net 2.0, my control is renamed
"ctl00$main$modifyCtrl", so I could use
getElementById("ctl00$main$modifyCtrl") to get my control and that would
work. Okay so far... But if a future version of asp.net changes the way it
mangles the name of the control to something else (like
"main$00$modifyCtrl"), then my client side code is screwed:
getElementById("clt100$main$modifyCtrl") would stop working. Am I right? If
I'm wrong, can you tell me why? But if I'm right, then my question now is:
what can I do on the client side to acces a control with a mangled name and
be sure the code doesn't break if Microsoft changes the naming convension?
Can I force asp.net 2.0 not to mangle with a control name? Thank you very
much for your help.

C.Levasseur
 
C

clintonG

You're not the only person who has not liked the control tree naming schema
but its there and we have to figure out how to work with it the way it is.
The best advice anybody could give you is to suggest you stop worring about
the future and work with what we have because change does happen anyway.

<%= Clinton Gallagher
 
I

intrader

But you're wrong about getElementById and you don't even write it correctly
so how could you know what you're talking about? I can help explain what I
know but I can't win an argument with someone who continues to argue the
facts just to argue about something.

Its a good thing though that your complaint will actually force you to learn
how and why you are misinformed as you're only other choice is to continue
trying to develop software misunderstanding what you think you are doing.

Finally, the .NET Framework manages the code and memory required to compile
and run the code. Right? You can think of it as your house or wherever you
live. If it didn't have an address the mail could not be delivered to the
right person. The control tree is the same analogy. Each control is a house
or an apartment and needs an adressing and identification schema so the mail
can be delivered to the right class.

That control tree was present in 1.1 but you do not understand how compilers
work. The 2.0 release is even more developer friendly and lets us see and
access more. You just need to learn how to think and see what it is. Go buy
some glasses :)

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
COME ON!, What kind of evasive, unfriendly answer is this!
 
C

C. Levasseur

Thanks for your help. This seems like a clean way to do what I want.
However, I would like to point out that the Visual Studio 2005 beta help
states that Page.RegisterStartupScript() is now obsolete... Maybe using
ClientScriptManager.RegisterClientScriptBlock() would be better?

C. Levasseur
 

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

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,158
Latest member
Vinay_Kumar Nevatia
Top