473,666 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changed controls IDs when using a MasterPage

WT
Hello,

It seems that when a control is set into a ContentPlaceHol der in a page
using a MasterPage, it's id is change and FindControl(ID) no more works, is
it normal, how to override this or retrieve the controls OnInit handler with
a FindControl ?
Thanks again for help.
CS
Feb 21 '07 #1
7 1976
anytime a control has a new parent, its name is changed. you can only
find a control from its immediate parent unless you use recursion. you
did not give enough detail to know what you are doing wrong.

-- bruce (sqlwork.com)

WT wrote:
Hello,

It seems that when a control is set into a ContentPlaceHol der in a page
using a MasterPage, it's id is change and FindControl(ID) no more works, is
it normal, how to override this or retrieve the controls OnInit handler with
a FindControl ?
Thanks again for help.
CS

Feb 21 '07 #2
Hi there,

I think i know what his problem is. DO NOT rely on server control's ID
property neither in CSS style sheets nor javasctript - NEVER!!!. It is not
quaranteed rendered client id is the same as ID.

YOU MAY NOT DO SUCH TRICKS!!!!
<style type="text/css">
#myTextBox
{
font-size: 10pt;
}
</style>

<asp:TextBox ID="myTextBox" runat="server"/>

it will ONLY work only if text box is placed directly on page that has no
master page defined. If you use masterpage with content placeholder, or any
other parent control, id generated in HTML will include all parent controls
id.

--
Milosz
"WT" wrote:
Hello,

It seems that when a control is set into a ContentPlaceHol der in a page
using a MasterPage, it's id is change and FindControl(ID) no more works, is
it normal, how to override this or retrieve the controls OnInit handler with
a FindControl ?
Thanks again for help.
CS
Feb 21 '07 #3
Hi CS,

FindControl only finds direct child in the control container. Controls put
into a ContentPlaceHol der will need to use the ContentPlaceHol der to find
the controls since the ContentPlaceHol der is a naming container (implements
INamingContaine r).

#Control.Naming Container Property (System.Web.UI)
http://msdn2.microsoft.com/en-us/lib....namingcontain
er.aspx

#Accessing ASP.NET Controls Programmaticall y
http://msdn2.microsoft.com/en-us/library/ms178509.aspx

#How to find child controls that are located in the template of a parent
control
http://support.microsoft.com/kb/323261

#ASP.Net 2.0 - Master Pages: Tips, Tricks, and Traps
http://www.odetocode.com/Articles/450.aspx
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 22 '07 #4
WT
Hi,

Thanks for answer, yes it is unusable with masterpages.
I was working serverside, not client, I discovered that using findcontrol
was a very complicated method as using object generated by asp.net for the
controls was working, and theses objects instances have the name of the
ID...that has changed after. So it is Ok until v3....
CS
"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.pla écrit dans le message
de news: A5************* *************** **...icrosof t.com...
Hi there,

I think i know what his problem is. DO NOT rely on server control's ID
property neither in CSS style sheets nor javasctript - NEVER!!!. It is not
quaranteed rendered client id is the same as ID.

YOU MAY NOT DO SUCH TRICKS!!!!
<style type="text/css">
#myTextBox
{
font-size: 10pt;
}
</style>

<asp:TextBox ID="myTextBox" runat="server"/>

it will ONLY work only if text box is placed directly on page that has no
master page defined. If you use masterpage with content placeholder, or
any
other parent control, id generated in HTML will include all parent
controls
id.

--
Milosz
"WT" wrote:
>Hello,

It seems that when a control is set into a ContentPlaceHol der in a page
using a MasterPage, it's id is change and FindControl(ID) no more works,
is
it normal, how to override this or retrieve the controls OnInit handler
with
a FindControl ?
Thanks again for help.
CS

Feb 22 '07 #5
WT
Thanks one more time, very usefull.
CS
"Walter Wang [MSFT]" <wa****@online. microsoft.coma écrit dans le message
de news: kN************* *@TK2MSFTNGHUB0 2.phx.gbl...
Hi CS,

FindControl only finds direct child in the control container. Controls put
into a ContentPlaceHol der will need to use the ContentPlaceHol der to find
the controls since the ContentPlaceHol der is a naming container
(implements
INamingContaine r).

#Control.Naming Container Property (System.Web.UI)
http://msdn2.microsoft.com/en-us/lib....namingcontain
er.aspx

#Accessing ASP.NET Controls Programmaticall y
http://msdn2.microsoft.com/en-us/library/ms178509.aspx

#How to find child controls that are located in the template of a parent
control
http://support.microsoft.com/kb/323261

#ASP.Net 2.0 - Master Pages: Tips, Tricks, and Traps
http://www.odetocode.com/Articles/450.aspx
Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Feb 22 '07 #6
Hi there again,

The rule is : never use server control ID for CSS and javascript. Period. i
didn't mean master pages only, it would stop working if you place control
inside another control, gridview, panel, repeater. Even if it seemed to be
working, it's very easy to screwed it up by adding controls, and then
spending hours finding the bug :)

use css class names instead.

--
Milosz
"WT" wrote:
Hi,

Thanks for answer, yes it is unusable with masterpages.
I was working serverside, not client, I discovered that using findcontrol
was a very complicated method as using object generated by asp.net for the
controls was working, and theses objects instances have the name of the
ID...that has changed after. So it is Ok until v3....
CS
"Milosz Skalecki [MCAD]" <mi*****@DONTLI KESPAMwp.pla écrit dans le message
de news: A5************* *************** **...icrosof t.com...
Hi there,

I think i know what his problem is. DO NOT rely on server control's ID
property neither in CSS style sheets nor javasctript - NEVER!!!. It is not
quaranteed rendered client id is the same as ID.

YOU MAY NOT DO SUCH TRICKS!!!!
<style type="text/css">
#myTextBox
{
font-size: 10pt;
}
</style>

<asp:TextBox ID="myTextBox" runat="server"/>

it will ONLY work only if text box is placed directly on page that has no
master page defined. If you use masterpage with content placeholder, or
any
other parent control, id generated in HTML will include all parent
controls
id.

--
Milosz
"WT" wrote:
Hello,

It seems that when a control is set into a ContentPlaceHol der in a page
using a MasterPage, it's id is change and FindControl(ID) no more works,
is
it normal, how to override this or retrieve the controls OnInit handler
with
a FindControl ?
Thanks again for help.
CS


Feb 22 '07 #7
Hi CS,

What Milosz described is mostly about the client-side ID (Control.Client ID:
http://msdn2.microsoft.com/en-us/lib....clientid.aspx
) generated from server-side controls. Which is a different concept (though
related) to the server-side ID (Contro.ID:
http://msdn2.microsoft.com/en-us/lib...ntrol.id.aspx).

Another "ID" is Control.UniqueI D.

To differentiate these three types of ID, please refer to following related
resources:

#Client Script in ASP.NET Web Pages
http://msdn2.microsoft.com/en-us/lib...2a(VS.80).aspx

#Shane's Blog - ASP.NET: Web Controls have an ID, a ClientID and a
UniqueID. What's the deal?
http://www.shanebauer.com/Weblog/Per...400b-aacf-e94d
4da9b533.aspx

Anyway, please feel free to let me know if you still have any questions
regarding these properties and where/when to use them accordingly.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.
Feb 23 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3904
by: sck10 | last post by:
Hello, I am looping through each control using the following to find a particular control (strFindCtl = "tbxCompetitor" & strForLoop1 & "Product"). For ctrRow = 1 To 3 strForLoop1 = "0" & ctrRow strFindCtl = "tbxCompetitor" & strForLoop1 & "Product" For Each ctlMaster As Control In Page.Controls ' Page If TypeOf ctlMaster Is MasterPage Then '
1
3246
by: Jaime Stuardo | last post by:
Hi all.... I am programming in ASP.NET 2.0 and VS.NET 2005 Beta 2. I have a MasterPage that provides basic look & feel for my pages. The main form present in the master page has this element: <form .... runat="server"> ........
3
6189
by: Ron | last post by:
Hi all, I've come across a problem when casting user controls in ASP.NET 2.0, hopefully someone can help. I have a master page with a user control on it (myMenu) that I wish to programmatically access from a content page. Below is how I am trying to do this (this would work in ASP.NET 1.1). DynamicMenu myMenu = (DynamicMenu)((MasterPage)this.Master).FindControl("myMenu");
2
3078
by: Scott | last post by:
I'm using a master page (mp_TableMaint.aspx) with one Content area (ID: Content1). Content1 contains several usercontrols, which are hidden. The goal is to show the correct control based on the querystring passed when calling mp_TableMaint (the page is called from an ASP.NET 2.0 Menu control on my index.aspx page). I believe I understand correctly that the Master Page's ASP Content control (named Content1) is, itself, a server side...
0
1093
by: Adam Tibi | last post by:
Hello, I have this: MasterPage 1: <asp:ContentPlaceHolder ID="cphHead" runat="server"> </asp:ContentPlaceHolder> Some Html... <asp:ContentPlaceHolder ID="cphBody1" runat="server"> </asp:ContentPlaceHolder>
1
1182
by: dawg1998 | last post by:
I have a page that creates dynamic textboxes based on the number of fields a user chooses to fill out. Basically, I am able to create the controls via this method (with other details): Dim txtbxTextBox as New Textbox() Form.Controls.Add(txtbxTextBox1) Then, when the page is submitted (via Postback) I grab the value in the textbox like so:
1
1080
by: RicercatoreSbadato | last post by:
hi all i'm using asp.net 2 and the master page paradigm in another page .aspx - that inherit from the master page - i'd like to has - programmatically - all the controls in the page, how can I do ? if I use this.Controls
2
3728
by: =?Utf-8?B?a2V2aW4=?= | last post by:
using VS2005 My masterpage has two panels and two hyperlinks. The initial content aspx page is blank. The page_load event of the masterpage hides one of the panels based on SESSION variables. When I press one particular link all controls are null, thus throwing an error. The other hyperlink behaves normally.
10
3584
by: Cirene | last post by:
I know that sometimes referring to controls deep in a page using a Master Page can be funky. For a website using a standard header/footer/nav, do you prefer using User Controls for the common items, or do you prefer Master Pages? What is best from your experience? I've downloaded a few sample projects (like for the Telerik Rad Controls) and have noticed that they like to use User Controls.
0
8876
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8784
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8556
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7387
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5666
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2774
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 we have to send another system
2
1777
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.