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 2 3121
On May 21, 3:23 am, Olorin <francesco.ri...@gmail.comwrote:
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
Hi,
A asp,net controls client id is generated according to where the
control reside...
i.e. if i add the control in a panel and then add the panel in
usercontrol and at last in page
client id will be usercontrolclientid+panelclientid
+controlclientid.....
if i change my control from one panel to another panel it will change
accordingly...
so its better to generate any script in onrender method of control
life cycle...
Thanks
Masudur
On May 21, 2:36 am, Masudur <munn...@gmail.comwrote:
so its better to generate any script in onrender method of control
life cycle...
Thanks
Masudur
Thanks, Masudur, your hint helped me out and I was able to make the
Freds and Wilmas work out as intended.
I was assuming that the Render method in CompositeControl would call
the CreateChildControls method (which I was overriding), but it turns
out that's not the case.
Thanks again,
~O. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: moondaddy |
last post by:
I have a user control being used instead of a frame page. when the user
clicks on a menu item I need to send the ID (integer value) of that menu as
a parameter in the postback of the user control...
|
by: Sanjay Pais |
last post by:
I built a custom control for all the basic web.ui.controls like textbox,
label, checkbox etc etc. I added my custom attribute called ApplySecurity to
the html in the page.
However, when I cycle...
|
by: Jeffrey Frabutt |
last post by:
Sorry about the repost... but my original post had funky characters
that was causing it to get truncated.
I've got a rather simple custom web control that has an object delcared
as...
|
by: david |
last post by:
I have developed a web form by using visual Studio. My question is:
(1) what is the problem?
(2) what is right way to do it?
In the form, there are labels with id:
lblWear, lblColor, and...
|
by: benoit |
last post by:
What is wrong with this code?
I get no errors on compilation of my assembly
But On compilation on my Webpage i keep getting this error
"Unable to find control id 'FreeBox1' referenced by the...
| |
by: Gonza |
last post by:
Hi group, i'm trying to add a customvalidator control to a custom web
control. The problem is i'm getting a "Unable to find control id..."
exception. Here is the code:
public class CuitTextBox :...
|
by: Mr. SweatyFinger |
last post by:
hi.
i have a bunch of controls that get validated with the validation controls
in vs2005
there are two that i could not find a control for so i wrote some
javascript.
so i set my submit...
|
by: TS |
last post by:
I have a custom textbox that i need to access a label's text property. the
label and textbox are 2 separate controls that will be on my page. Inside my
custom control i want to have access to this...
|
by: shapper |
last post by:
Hello,
I have a custom control named Parent where I used the following:
Protected Overrides Sub CreateChildControls()
...
MyBase.Controls.Add(MyTextBox)
MyBase.CreateChildControls()...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |