473,378 Members | 1,507 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Clearing Page's Control

Ali

I used to clear my page's control in Visual Studio 2003 using code like this:
Dim c As Control
For Each c In Page.Controls(1).Controls
If TypeOf c Is TextBox Then
CType(c, TextBox).Text = Nothing
End If
If TypeOf c Is DropDownList Then
CType(c, DropDownList).SelectedIndex = 0
End If
Next

It worked properly. Now I am using Visual Studio 2005 beta 1 version and I
am using Master Page for my forms. I used the same code but nothing happens
... clearing controls did not work ... seems they change the page's control
hierarchy when using master pages but I don't exactly know. Does anyone know
how can I fix the above code to make it work in my VS 2005 application?
Nov 19 '05 #1
4 4406
Hi Ali,

I am working in Whidby (VS.NET 2005) right now. The problem in the code is
that you need to take into account the master page form ID.

Run the form in the browser and then right click and view source. Now have a
look at the ID of the control(s). They will have a prefix of "ct100$..." or
something (this is what i had). This is a static value which will be appended
to all your controls in the page. Modify your code and append this value. It
will work fine.

Need any help, do post a msg back...
Happy Coding.

"Ali" wrote:

I used to clear my page's control in Visual Studio 2003 using code like this:
Dim c As Control
For Each c In Page.Controls(1).Controls
If TypeOf c Is TextBox Then
CType(c, TextBox).Text = Nothing
End If
If TypeOf c Is DropDownList Then
CType(c, DropDownList).SelectedIndex = 0
End If
Next

It worked properly. Now I am using Visual Studio 2005 beta 1 version and I
am using Master Page for my forms. I used the same code but nothing happens
.. clearing controls did not work ... seems they change the page's control
hierarchy when using master pages but I don't exactly know. Does anyone know
how can I fix the above code to make it work in my VS 2005 application?

Nov 19 '05 #2
Ali
Hi Vishnu,
Yes, you're right. I checked my code and found this:
<input name="ctl00$ContentColumn$Address" type="text"
id="ctl00_ContentColumn_Address" style="height:22px;width:183px;" />
<input name="ctl00$ContentColumn$city" type="text"
id="ctl00_ContentColumn_city" style="height:22px;width:183px;" />

Those two textboxes have IDs: address and city .. and as you said the
clt00$_ContentColumn_ appended to all controls' IDs on the page. Now i want
to know how to append this value to my code below .. what changes should I
make:

For Each c In Page.Controls(1).Controls
If TypeOf c Is TextBox Then
CType(c, TextBox).Text = Nothing
End If
Next
Thanx

"Vishnu-Chivukula" wrote:
Hi Ali,

I am working in Whidby (VS.NET 2005) right now. The problem in the code is
that you need to take into account the master page form ID.

Run the form in the browser and then right click and view source. Now have a
look at the ID of the control(s). They will have a prefix of "ct100$..." or
something (this is what i had). This is a static value which will be appended
to all your controls in the page. Modify your code and append this value. It
will work fine.

Need any help, do post a msg back...
Happy Coding.

"Ali" wrote:

I used to clear my page's control in Visual Studio 2003 using code like this:
Dim c As Control
For Each c In Page.Controls(1).Controls
If TypeOf c Is TextBox Then
CType(c, TextBox).Text = Nothing
End If
If TypeOf c Is DropDownList Then
CType(c, DropDownList).SelectedIndex = 0
End If
Next

It worked properly. Now I am using Visual Studio 2005 beta 1 version and I
am using Master Page for my forms. I used the same code but nothing happens
.. clearing controls did not work ... seems they change the page's control
hierarchy when using master pages but I don't exactly know. Does anyone know
how can I fix the above code to make it work in my VS 2005 application?

Nov 19 '05 #3
hi,

can anybody help me out the code in asp.net

i have used the following code. but it is not getting the output. Can
anybody check and tell me whether the following code is correct.

regards,

Sunil
------------------------------------------------------------------------

foreach (System.Web.UI.Control oChildControl in Page.Controls)
{
if
(oChildControl.GetType().ToString().Equals("System .Web.UI.WebControls.TextBox"))
{
bool TypeFlag = oChildControl.GetType().ToString();
}
}
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Nov 19 '05 #4
You want to loop through the Controls Collection of the form, not the Page.
The reason is that the Controls Collection of a Control is only 1 deep. That
is, if you have Controls nested inside other Controls, the Controls
Collection of any Control in the hierarchy is only the Controls immediately
below that Control, not any Controls inside those Controls.

The WebForm itself is a Control inside the Page Control.So, if you're
looking for a Control inside the Web Form, you look in its Controls
Collection.

It is also possible to create a recursive function that loops through the
Controls of a given Control, and then calls itself for each Control inside
that Control recursively.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"pvsunil" <su***@comcreation-dot-com.no-spam.invalid> wrote in message
news:42********@127.0.0.1...
hi,

can anybody help me out the code in asp.net

i have used the following code. but it is not getting the output. Can
anybody check and tell me whether the following code is correct.

regards,

Sunil
------------------------------------------------------------------------

foreach (System.Web.UI.Control oChildControl in Page.Controls)
{
if
(oChildControl.GetType().ToString().Equals("System .Web.UI.WebControls.TextBox"))
{
bool TypeFlag = oChildControl.GetType().ToString();
}
}
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Nov 19 '05 #5

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

Similar topics

0
by: Jeff Levinson [mcsd] | last post by:
Not as far as I know. The easiest way is just to create a loop to set all of the controls values to "". You'll probably have to use a typeof statement to come up with specific clearing methods for...
18
by: Niels | last post by:
Hi group, I have some problems with clearing floated divs. My usual method works fine in Konqueror, but not in Firefox. Here's an example: <html><body> <div id='left' style='float:left;...
2
by: Savvas | last post by:
Hi everybody, I have a lot of textboxes on my form and a "Clear" button. Is there a way with a for loop or something to clear the textboxes, instead of writing textboxName.clear? Thanks a lot
1
by: Tyros | last post by:
I'm new to C# and I'm dynamically creating a table control that contains a text control inside one of the cells. I load the values of each text field with an SQL call. The form is simple and I'm...
2
by: John Smith | last post by:
Hi folks, I have a form with ASP.NET web controls. At the end of the form there's the "Clear" button to clear the available values and start over. How do I do that? The following did not work...
1
by: RLN | last post by:
Re: Access 2003 I found a method here in the newsgroup that works for clearing checkboxes, but don't understand a particular line of code and how it works. Here is the code: 1. Dim ctrl As...
0
by: maflatoun | last post by:
Hello, I'm using the asp:CreateUserWizard on the bottom of a page with a search for users option on the top of the page. The issue that I'm running into is that everytime I add a new user and...
1
by: ray well | last post by:
i'm loading a combobox from a database in code, by setting the the DataSouce to a table, and the DisplayMember to a field. it loads the first row into the text area of the combobox automatically....
6
by: =?Utf-8?B?R2Vv?= | last post by:
Hi, I use lots of sessions. I want to clear the unwanted sessions when I leave a page. I cant use ViewState as it will slow down the pages. Could some one help me on this?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.