Over riding the Default ClientId Property

  • Thread starter Elizabeth Harmon
  • Start date
E

Elizabeth Harmon

Hi All

When .Net Creates User Controls on a Webpage, it appends a prefix seperated
by a Colon or an underscore then the Id of the server Control within that
User Control:

ex:

<asp:Dropdownlist id="DDLList" runat="server"></asp:DropDownList> in design
mode

<asp:Dropdownlist name="_ctrl0:DDLList" id="_ctrl0_DDLList"
runat="server"></asp:DropDownList> in run mode

I try to change the ID by setting the property of the DropDownList like
this:

DDLList.Id = "cmbDDLList"

But .Net retains the naming convention. Is there a way to get around this or
is this just what .Net Does?

if i use a placeholder and then Create the Object programmatically, i can
assign an ID and it keeps the name i assigned to the property.

I just thought after dragging and dropping there was a way on a user control
to retain the original Id i typed in for the Server control i droppped
there.

thanks in advance
 
J

John Saunders

Elizabeth Harmon said:
Hi All

When .Net Creates User Controls on a Webpage, it appends a prefix seperated
by a Colon or an underscore then the Id of the server Control within that
User Control:

ex:

<asp:Dropdownlist id="DDLList" runat="server"></asp:DropDownList> in design
mode

<asp:Dropdownlist name="_ctrl0:DDLList" id="_ctrl0_DDLList"
runat="server"></asp:DropDownList> in run mode

I try to change the ID by setting the property of the DropDownList like
this:

DDLList.Id = "cmbDDLList"

But .Net retains the naming convention. Is there a way to get around this or
is this just what .Net Does?

if i use a placeholder and then Create the Object programmatically, i can
assign an ID and it keeps the name i assigned to the property.

I just thought after dragging and dropping there was a way on a user control
to retain the original Id i typed in for the Server control i droppped
there.

Don't sweat the ID. It will be prefixed if it is placed within another
control which implements INamingContainer. It's best to leave this issue
alone and find another way to accomplish your task.
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top