Incorrect duplicate ID added to server control, leaving it with 2 IDs

A

aaron

Hi All,

I have a custom web control which works perfectly. Its just a
tabcontrol to spit out navigation tabs, it inherits from
System.Web.UI.WebControls.WebControl

In web page design view, say I give the control an ID of "tab1".

I am getting this weird and very frustrating behaviour:

When the page is rendered, i.e. if you go "View Source" from the
browser, the next server control placed on the page after the "tab1"
control, ends up with two IDs. The first ID is "tab1" (somehow
incorrectly carried over from the "tab1" control above it), and the
second ID is the control's correct ID which it should have, i.e.
"pnlSearch" or something.
In my case, its a Panel that's copping the extra incorrect ID, but I've
tried removing the panel and replacing it with any other server
control, i,e, an <asp:Label> or anything, and as long as its the next
control straight after my "tab1", it ends up having an id="tab1" added
to it incorrectly!

So the panel looks like this when rendered:
<div id="tab1" id="pnlSearch">

I'm using a lot of CSS, so this multiple ID rubbish is causing me some
grief.

I'm pretty certain something could be not quite spot on with the custom
TabControl. When I remove it, the problem goes away. Its almost like
the TabControl is leaving some variable set with its ID in it, and the
next server control is picking that up and using it, but it needs to be
cleared or something..

Thanks for any insight into this..

Aaron.
 
A

aaron

I have kludged it with a dodgy hack to overcome my problem for now.

Underneath the TabControl, I just placed this:
<asp:Label id="anotherdotnetworkaround" runat="server"></asp:Label>

Then when rendered, the label becomes a span with the two IDs, i.e.:
<span id="tab1" id="anotherdotnetworkaround"></span>

So now my pnlSearch doesn't confuse the CSS as it only has 1 ID like it
should. And I don't use the redundant workaround span, it just sits
there like a dodgy kludge bloating the document source by a few bytes.

Just so annoying!
 
K

Kevin Jones

Is your control a composite, i.e. is it creating other controls, or are
the tabs just spat out as HTML. If it is a composite, are you
implementing INamingContainer?

Kevin
 

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,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top