![]() |
|
|
|||||||
![]() |
ASP Net - Loop through webform controls - please help me |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Hi everyone,
I'd like to interrogate a web form to check for values of the controls on the form. The following codes worked when I execute it in a User Control that has some web controls on it but I can't seem to get it to work directly on the form itself. using System.Web; using System.Web.UI; using System.Web.UI,WebControls; foreach (Control ctrl in this.Controls) { if (ctrl is TextBox) do something else if (ctrl is DropDownList) do something else } When the above code is done at the Page_Load() of the aspx file, the this.Controls return System.Web.UI.LiteralControl, System.Web.UI.HTMLControls etc in the Controls collection but not the Textboxes and other Web Controls. Is this correct or have I done something wrong? It'd be greatly appreciated if someone out there can enlighten me please. KD =?Utf-8?B?Q2FsdmluIEtE?= |
|
|
|
|
#2 |
|
Posts: n/a
|
Hi Calvin,
In "this" case, "this" is a reference to the Page itself. The Form is a Control IN the Page. All Controls inside the Form are inside the Form's Controls Collection, not the Page's. -- HTH, Kevin Spencer Microsoft MVP ..Net Developer Ambiguity has a certain quality to it. "Calvin KD" <> wrote in message news:2DC1CD94-23FC-47AF-BF7B-... > Hi everyone, > I'd like to interrogate a web form to check for values of the controls on > the form. The following codes worked when I execute it in a User Control > that > has some web controls on it but I can't seem to get it to work directly on > the form itself. > > using System.Web; > using System.Web.UI; > using System.Web.UI,WebControls; > > foreach (Control ctrl in this.Controls) > { > if (ctrl is TextBox) > do something > else if (ctrl is DropDownList) > do something else > } > > When the above code is done at the Page_Load() of the aspx file, the > this.Controls return System.Web.UI.LiteralControl, > System.Web.UI.HTMLControls > etc in the Controls collection but not the Textboxes and other Web > Controls. > Is this correct or have I done something wrong? > It'd be greatly appreciated if someone out there can enlighten me please. > KD Kevin Spencer |
|
|
|
#3 |
|
Posts: n/a
|
Thanks so much Kevin. Is this by design or is it a bug by MS? What's really
frustrating is that the Watch Windows does not have the correct Controls collection so I could not find out that there exists a "second level" and this is certainly not the case for Windows forms and may be VB.Net ? "Kevin Spencer" wrote: > Hi Calvin, > > In "this" case, "this" is a reference to the Page itself. The Form is a > Control IN the Page. All Controls inside the Form are inside the Form's > Controls Collection, not the Page's. > > -- > HTH, > > Kevin Spencer > Microsoft MVP > ..Net Developer > Ambiguity has a certain quality to it. > > "Calvin KD" <> wrote in message > news:2DC1CD94-23FC-47AF-BF7B-... > > Hi everyone, > > I'd like to interrogate a web form to check for values of the controls on > > the form. The following codes worked when I execute it in a User Control > > that > > has some web controls on it but I can't seem to get it to work directly on > > the form itself. > > > > using System.Web; > > using System.Web.UI; > > using System.Web.UI,WebControls; > > > > foreach (Control ctrl in this.Controls) > > { > > if (ctrl is TextBox) > > do something > > else if (ctrl is DropDownList) > > do something else > > } > > > > When the above code is done at the Page_Load() of the aspx file, the > > this.Controls return System.Web.UI.LiteralControl, > > System.Web.UI.HTMLControls > > etc in the Controls collection but not the Textboxes and other Web > > Controls. > > Is this correct or have I done something wrong? > > It'd be greatly appreciated if someone out there can enlighten me please. > > KD > > > =?Utf-8?B?Q2FsdmluIEtE?= |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| loop according to the delay | kavidream24 | Software | 0 | 12-23-2008 02:18 AM |
| I just want to know how to create a new webform in asp .net dynamically... | nkamalraj | Software | 1 | 05-28-2006 04:28 AM |
| VLC controls | DVDfanatico | DVD Video | 1 | 01-25-2006 05:22 PM |
| VLC controls | DVDfanatico | DVD Video | 2 | 01-25-2006 12:07 AM |
| Getting Around Copy Controls | Ablang | DVD Video | 0 | 04-01-2005 06:09 AM |