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
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

    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


    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


    LVL 4

    Assisted Solution


    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.

    LVL 2

    Author Comment

    by:Brandy Vaughn
    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now