[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Can you stop .NET from adding the UserControl id to the form element id's in a web user control

Posted on 2004-11-08
Medium Priority
Last Modified: 2012-08-14
I'm trying to find out if there is a setting available in .NET that I can change so that it does not change my form element names in my web user controls at run time. For example if I have a form element named txtName in a web user control named Test, .NET generates the ClientID or form element name of Test_txtName, and I don't want this to happen. I currently have a lot of javascript referencing the id I assign, and it will be a lot of work to change it. I already know that I can change the javascript to document.getElementByID("Test_txtName"), but I'm trying to avoid changing all the script.

Thanks Brandy
Question by:Brandy Vaughn
LVL 28

Assisted Solution

mmarinov earned 450 total points
ID: 12527676
Hi brandybateman,

i'm not quite sure - but i don't think you can
but, you can try with putting your user control inside Literal Control

LVL 10

Accepted Solution

lengreen earned 450 total points
ID: 12527695

Not sure if this is possible as the way it names them is inherent to the way viewstate works. But its not something i tried so it will be interesting to see if I am wrong



Assisted Solution

Glom earned 450 total points
ID: 12532831

You can't stop .NET from adding this, because it needs it to retreive the control.

However, to avoid this problem, you can use the UniqueID in your control javascript instead of the ID. The UniqueID will remain always the same for each control you create. Even if it is placed on an .ascx.


Author Comment

by:Brandy Vaughn
ID: 12535323
Well I guess it's not possible to stop .NET from adding the control id to the id and name of the html controls and web controls. I was going through all my javascript and changing it to document.getElementByID("User Control id_Element id") and this did work for the most part, but when I would change an element value in javascript, .NET didn't recognize the new value. Any way to make a long story short, after a couple of days of frusteration I realized that I was changing web forms into web user controls when they should have stayed web forms, so I didn't need to change anything after all. I was having a backwards day or two.

mmarinov, I wasn't really sure what you meant by putting the user control inside a literal control. Isn't a literal control a string? Anyway, I do think you are right that I can't stop .NET from generating the id's and name's at runtime.

Glom, when I was playing with the UniqueID and the ClientID I noticed that the UniqueID is generated as "User Control id:Element id" and the ClientID is generated as "User Control id_Element id", so I wasn't really sure what you meant by the UniqueID will remain always the same for each control you create. Both the ClientID and UniqueID of the html controls and web controls are changed at runtime by .NET if they are placed in a .ascx file.

I'm going to try and split the points between the 3 of you, and if it fails I'll give the points to mmarinov because he was the first to reply.

Thanks everyone for your quick replies.


Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question