|
|
||||||
|
#1
|
|
|
|
|
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 |
|
|
|
#2
|
|
|
|
|
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. Levasseur" <clevasseur> wrote in message news:a156 [..] |
|
#3
|
|
|
|
|
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" /> "clintonG" <csgallagher> wrote in message news:2644 [..] |
|
#4
|
|
|
|
|
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. Levasseur" <clevasseur> wrote in message news:2312 [..] |
|
#5
|
|
|
|
|
"C. Levasseur" <clevasseur> wrote in message
news:2312 > But my problem is on the client side... GetElementById() is on the server > side. getElementByID() is JavaScript i.e. client-side... |
|
#6
|
|
|
|
|
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 |
|
#7
|
|
|
|
|
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 "C. Levasseur" <clevasseur> wrote in message news:3756 [..] |
|
#8
|
|
|
|
|
On Sat, 08 Oct 2005 22:05:39 -0500, clintonG wrote:
[..] > NET csgallagher AT metromilwaukee.com > URL [..] > URL [..] >> >> "C. Levasseur" <clevasseur> wrote in message > news:2312 COME ON!, What kind of evasive, unfriendly answer is this! |
|
#9
|
|
|
|
|
Hi -- take a look at this:
http://uzair.nairang.org/articles/20...-name-mangling Cheers, Syed *** Sent via Developersdex http://www.developersdex.com *** |
|
#10
|
|
|
|
|
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 "Syed Aqeel" <dontemailme> wrote in message news:3000 [..] |
|
#11
|
|
|
|
|
Page.RegisterStartupScript() Is now obsolete.
Use System.Web.UI.ClientScriptManager.RegisterStartupS cript See : http://msdn2.microsoft.com/en-us/lib...tartups cript Juan T. Llibre, ASP.NET MVP ASP.NET FAQ : [url down] Foros de ASP.NET en Espaņol : [url down] ====================================== "C. Levasseur" <clevasseur> wrote in message news:2960 [..] |
|
|
| Similar Threads | |
| .NET renaming my controls Is there a way to tell the VS2005 IDE NOT to rename my controls on a build? if my control name is txtDate, the rendered version of the page has the control as... |
|
| VBA Renaming Controls This has happened about 4 times already so I am about to scrap VBA as a solution for anything. Without having ANY other Word docs with VBA controls on them open, Word is... |
|
| Renaming controls en-mass I have a form with over 50 controls where I need to change the names of all the controls (according to a rule). Is there any way I can do this from code or do I have to do... |
|
| renaming array of controls from the default CommandButton1,2,3........100. to MyCmb1,2,3.....100 I tried Dim x As Single |
|
|
All times are GMT. The time now is 06:33 PM. | Privacy Policy
|