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

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
Brandy VaughnAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


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



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

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.

Brandy VaughnAuthor Commented:
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.