O
Olorin
I'm encountering some weird behavior with the ClientID property. Let's
see if I can give you enough info and if anyone has ideas/suggestions.
I'm working in ASP.NET 2.0. I have a Web Project with a master page,
with a single ContentPlaceholder on it.
I have a page that uses that Master template, and is meant to place 2
controls of type Fred in the content placeholder. The .aspx for this
page goes like this:
[register tag prefix cc to grab custom controls from a separate
project]
....
<asp:Content ID="Content1"
ContentPlaceHolderID="contentPlaceholder_Workarea" runat="server">
<cc:Fred runat="Server" ID="fred_1" />
<cc:Fred runat="Server" ID="fred_2"></cc:Fred>
</asp:Content>
The Fred control is actually a custom control I defined as inheriting
from CompositeControl. Fred overrides TagKey to return
HtmlTextWriterTag.Div. It also overrides CreateChild Control to do a
few things, among which, it adds a System.Web.UI.WebControls.Panel
named Wilma to its Controls. When I add a Wilma to the controls, I add
an attribute to it like this:
myWilma.Attributes.Add("onclick", "alert('"+this.ClientID+"');");
It all works quite nicely, and the Wilma's have the Freds' mangled Ids
(e.g.: onclick="alert('ctl00_contentPlaceholder_Workarea_fred_1')")
available.
However, if I put anything (and I mean anything, even a space
character, a newline character, ...) between the opening and closing
tags of a Fred control, like this:
<cc:Fred runat="Server" ID="fred_2"> </cc:Fred>
Then Wilma's onclick event gets an un-mangled version of Fred's ID
(e.g.: onclick="alert('fred_2');" ).
It seems that I'm missing some crucial step/aspect that makes my
controls' Client IDs go out of sync.
I have checked fred_2's ClientID from the surrounding page Page_Load
method, and it is mangled at that time.
So, the difference is between the times when Page_Load and the
control's CreateChildControls methods run...
Any suggestion ?
Thanks in advance,
Frank
see if I can give you enough info and if anyone has ideas/suggestions.
I'm working in ASP.NET 2.0. I have a Web Project with a master page,
with a single ContentPlaceholder on it.
I have a page that uses that Master template, and is meant to place 2
controls of type Fred in the content placeholder. The .aspx for this
page goes like this:
[register tag prefix cc to grab custom controls from a separate
project]
....
<asp:Content ID="Content1"
ContentPlaceHolderID="contentPlaceholder_Workarea" runat="server">
<cc:Fred runat="Server" ID="fred_1" />
<cc:Fred runat="Server" ID="fred_2"></cc:Fred>
</asp:Content>
The Fred control is actually a custom control I defined as inheriting
from CompositeControl. Fred overrides TagKey to return
HtmlTextWriterTag.Div. It also overrides CreateChild Control to do a
few things, among which, it adds a System.Web.UI.WebControls.Panel
named Wilma to its Controls. When I add a Wilma to the controls, I add
an attribute to it like this:
myWilma.Attributes.Add("onclick", "alert('"+this.ClientID+"');");
It all works quite nicely, and the Wilma's have the Freds' mangled Ids
(e.g.: onclick="alert('ctl00_contentPlaceholder_Workarea_fred_1')")
available.
However, if I put anything (and I mean anything, even a space
character, a newline character, ...) between the opening and closing
tags of a Fred control, like this:
<cc:Fred runat="Server" ID="fred_2"> </cc:Fred>
Then Wilma's onclick event gets an un-mangled version of Fred's ID
(e.g.: onclick="alert('fred_2');" ).
It seems that I'm missing some crucial step/aspect that makes my
controls' Client IDs go out of sync.
I have checked fred_2's ClientID from the surrounding page Page_Load
method, and it is mangled at that time.
So, the difference is between the times when Page_Load and the
control's CreateChildControls methods run...
Any suggestion ?
Thanks in advance,
Frank