473,769 Members | 4,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Iterating Controls on ContentPlaceHol der

Hi,

I am trying to iterate though the controls on a content page that has a
master page so I can disable text. If it weren't on a content page it is
simple:

foreach (Control c in Page.Controls)
{
if (c is TextBox)
{
(TextBox)c.Enab led = false;
}
}

I can't figure out how to get the ClientID into this to deal with the
mangled names.

thanks,
Bill
Mar 3 '06 #1
2 2571
as controls are nested in controls, you need to recurse thru all controls

void DisableAllTextB oxes(Control ctl)
{
if (ctl is TextBox)
(TextBox) ctl.Enabled = false;
foreach (Control c in ctl.Controls)
{
DisableAllTextB oxes(c);
}
}

-- bruce (sqlwork.com)

"Bill44077" <Bi*******@disc ussions.microso ft.com> wrote in message
news:13******** *************** ***********@mic rosoft.com...
Hi,

I am trying to iterate though the controls on a content page that has a
master page so I can disable text. If it weren't on a content page it is
simple:

foreach (Control c in Page.Controls)
{
if (c is TextBox)
{
(TextBox)c.Enab led = false;
}
}

I can't figure out how to get the ClientID into this to deal with the
mangled names.

thanks,
Bill

Mar 3 '06 #2
Hi Bruce,

Thanks much for the quick reply. I'm not sure what control to pass in to
begin the recursion. The problem with the example that I gave is that
Page.Controls seems to be looking at the master page rather than the content
page where the controls are that I want to disable. Also, if I place this
function in my code beside it give a compile error:
Error 23 'System.Web.UI. Control' does not contain a definition for
'Enabled' C:\KEY\KPO\BZP\ AuthenticatedWe b\QuoteSummary. aspx.cs 1293 26 C:\...\Authenti catedWeb\

flagging the .Enable property. I'm probabaly overlooking something but I'm
not sure what.

regards!
Bill
"Bruce Barker" wrote:
as controls are nested in controls, you need to recurse thru all controls

void DisableAllTextB oxes(Control ctl)
{
if (ctl is TextBox)
(TextBox) ctl.Enabled = false;
foreach (Control c in ctl.Controls)
{
DisableAllTextB oxes(c);
}
}

-- bruce (sqlwork.com)

"Bill44077" <Bi*******@disc ussions.microso ft.com> wrote in message
news:13******** *************** ***********@mic rosoft.com...
Hi,

I am trying to iterate though the controls on a content page that has a
master page so I can disable text. If it weren't on a content page it is
simple:

foreach (Control c in Page.Controls)
{
if (c is TextBox)
{
(TextBox)c.Enab led = false;
}
}

I can't figure out how to get the ClientID into this to deal with the
mangled names.

thanks,
Bill


Mar 3 '06 #3

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

Similar topics

2
3911
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 '
2
1465
by: Urs Eichmann | last post by:
Hello, I want to define a MasterPage which already has some asp:Textbox and other controls defined inside a ContentPlaceHolder. The idea is that the user of the master page just changes two or three properties of these "predefined" controls and has everything right in place. I realize I could program an ASCX or Webcontrol instead and let the users put that on the page themselves. But I would prefer if it was already predefined in the...
6
6468
by: Ryo | last post by:
Hello ! I have an .aspx page that use a master page. I want to do a for each that list all controls on this page. I have try something like: foreach (System.Web.UI.Control wct in this.Controls) But there are only one control returned, the ASP.Design_master control. An idea ? Thanks.
2
3089
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
1102
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>
5
3858
by: Dave H | last post by:
I was doing this in a .Net 1.1 site, but it doesn't work in 2.0, because the objects aren't public (I think) For k = 1 To iDDLCount ddlObject = CallByName(oParent, sDDLName & k, CallType.Get) ddlObject.Items.Clear() Next Any ideas?
7
1984
by: WT | last post by:
Hello, It seems that when a control is set into a ContentPlaceHolder 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
8
8947
by: =?Utf-8?B?Q2hyaXMgSGFsY3Jvdw==?= | last post by:
Hi there I've successfully added some .NET validation controls to a page (using <asp:RequiredFieldValidator ...), however when I try to set the 'display' property to 'dynamic', my page then throws up the following error in the browser: CS1061: 'System.Web.UI.WebControls.TextBox' does not contain a definition for 'Web' and no extension method 'Web' accepting a first argument of type 'System.Web.UI.WebControls.TextBox' could be found...
2
1221
by: Brian Lowe | last post by:
I'm trying to add the content of a user control dynamically at run time, dependent upon some request attribute. My user control is a simple tell-tall so I'm sure that's not spoiling anything. <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="cpStatus.ascx.cs" Inherits="uc.cpStatus" %> <p>status indicator for special users</p>
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9987
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
9857
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7404
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
6662
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
5294
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...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.