clearing all text boxes on a web form

Howdy, I picked up the following code a while back but have only now had the time to try it.

what I would like to do is clear the content of all the text boxes on a web form.
here is the code:
 Private Sub ReadControls() 

Dim ctl As Control
Dim intIndex As Integer
' First find the Form object
For Each ctl In Page.Controls
If ctl.GetType Is GetType(Web.UI.HtmlControls.HtmlForm) Then
intIndex = Page.Controls.IndexOf(ctl)
Exit For
End If
Next
' Loop through all controls within Form Control
' which is at Postion 1 in the Controls Collection
For Each ctl In Page.Controls.Item(intIndex).Controls
If ctl.GetType Is GetType(TextBox) Then
Response.Write(CType(ctl, TextBox).ID & " = ")
Response.Write(CType(ctl, TextBox).Text & "")
End If
Next

everything seemed to be going fine, it correctly detects the textboxes.
but then it seems to simply write the values to the screen...
Response.Write(CType(ctl, TextBox).ID & " = ") 

Response.Write(CType(ctl, TextBox).Text & "")

I must be missing something simple.
I tried to access the <code>ctl.TEXT<\code>
attribite of the control, but it is not available...I'm guessing that it is because it is declared as a generic control.can anyone help me out?I'd say there's a few folk out there who'd be keen on putting this one to bed.
it all seemed so easy in vb6.
Many thanks,
yogi


buy an old van and drive round oz.
0
cyoker
4/30/2003 10:53:19 PM
asp.net.getting-started 91979 articles. 3 followers. Follow

8 Replies
642 Views

Similar Articles

[PageSpeed] 43

..
0
wisemonk
5/1/2003 2:08:11 AM
thanks bud.

got it in one.
cheers,
yogi
buy an old van and drive round oz.
0
cyoker
5/1/2003 9:43:30 AM
Can someone explain this code for me 

What I'm wondering is what does the first loop do? Can I skip it?
thanks.

Dim ctl As Control
Dim intIndex As Integer
' First find the Form object
For Each ctl In Page.Controls
If ctl.GetType Is GetType(Web.UI.HtmlControls.HtmlForm) Then
intIndex = Page.Controls.IndexOf(ctl)
Exit For
End If
Next

' Loop through all controls within Form Control
' which is at Postion 1 in the Controls Collection
For Each ctl In Page.Controls.Item(intIndex).Controls
If ctl.GetType Is GetType(TextBox) Then
Dim txtbx As TextBox
txtbx = CType(ctl, TextBox)
txtbx.Text = ""
End If
If ctl.GetType Is GetType(ListBox) Then
Dim txtbx As ListBox
txtbx = CType(ctl, ListBox)
txtbx.SelectedIndex = 0
End If
Next

Daniel
0
dbogey
10/29/2003 8:42:24 PM
The first loop tries to find the Form on the page. It would be more efficient to retain the reference to the form control instead of just keeping its index, though.

The problem with this code is that it won't find all textboxes but only the textboxes that are directly under the form.
You would need to make a function that recursively explores the Control tree to be really complete.
Bertrand
----
This posting is provided "AS IS" with no warranties, and confers no rights.
0
bleroy
10/29/2003 10:19:08 PM
What other textboxes would there be?  When you say only in the form.  Can you give an example of when it would not be in the form.  Sorry so brief, but I'm out the door (Mom's Birthday).

thanks.
Daniel
0
dbogey
10/29/2003 11:21:20 PM
TextBoxes in a NamingContainer inside the form. Controls form a tree, and that can be deep.

Example: textboxes in a repeater.
Bertrand
----
This posting is provided "AS IS" with no warranties, and confers no rights.
0
bleroy
10/30/2003 12:55:39 AM
Most of what I'm doing is database lookup, insert....  In my scenario I'd bring back data into a single form and not repeater controls.  What I've posted works great.  I've included textboxes, dropdownlists, radiobuttonlists and such.

Thanks for the quick replies. I really enjoy working with asp.net comming from cold fusion.
Again Thanks :)
Daniel
0
dbogey
10/30/2003 2:49:29 AM
Sure, it works in most cases.

I was just mentioning it so that other people who have the same problem but have nested stuff can figure it out and make it work too.
:)
Bertrand
----
This posting is provided "AS IS" with no warranties, and confers no rights.
0
bleroy
10/31/2003 1:07:23 AM
Reply:

Similar Artilces:

VB .net Web Form will not get contents of Text Box
I have created a web form with text boxes that are bound to a DataSet/DataView.  I have created button to navigate up and down the recordset.  That all works fine. I need to have the ability to edit/add text in any of the boxes and then when clicking "Save" button, it would build an UPDATE query to send to the database. When the Save button is clicked, I have coded to DIM a string var (strSQL) to use to build the SQL command.  For some reason, it will only get the text from a text box if the data was pulled the database.  If I add/edit data, then the SQL command will ha...

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin = window.open('foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script> &...

Getting error while disabling the text boxes on Web Form
Hello Folks...THis is very urgent ...Plz help...Following is a piece of code....to disable all the textBoxes on a WebForm in ASP.Net.(Lang:VB.Net) Private Sub disableAllTextBoxes(ByVal ControlArray) Dim control As Object Dim temptxtbox Dim i As Integer For Each control In ControlArray       If control.GetType.Name = "TextBox" Then          control.GetType.GetTypeArray(control).CopyTo(temptxtbox, 0)          For i = 0 To UBound(temptxtbox)     &n...

Possible to clear all the text boxes on a web form with a single command?
Hi all, I want to clear all the text boxes of a web form. At present, what I do is : I set it as follows. Textbox1.text = "" Textbox21.text = "" Textbox3.text = "" etc. etc ............ Is it possible for me to clear all the text boxes at a strech? Thanking you in advance, Tomy below is a function which will loop through all the textboxes in a webform and clear them private void ClearTextBox(Control c) { foreach(Control ctr in c.Controls) { foreach(Control cc in ctr.Controls) { if(cc is TextBox) ((TextBox)(cc)).Text = string.Empty; } } } now wheneever u need to use it j...

getting start with vb.net and crystal repots(web form)
I use Crystal Report9 in Visual Studio.NET 2003..... Example at Northwind database I want a application that.....a form include a combobox that contain CustomerID.....If I choose one CustomerID and click OK button....a Report will display information about this Customer......I think that must use Paramater.....how to do that ???? (How do I start to coding --please step by step or sample) please help me !!! Thank you so much!!! very good I have Dropdownlist when I choose the 'month'--> the all data of this field will show I use this Private Sub ddlMonth_Sel...

How to clear all text boxes on the form using a function on form
I want to use the following to clear all th text boxes on the form, but it complains on the following line: cntl.text = "" it says text is not a member of cntl. Can you please correct the code. Private Sub Cleartextboxes() Dim cntl As Control For Each cntl In Me.Controls If TypeOf cntl Is TextBox Then cntl.Text = "" End If Next End Sub Thank you very much for the information. Hi, you would need to cast the control to a TextBox before you can access Text...

Dropdown selected index and text box text not getting reflected on web page
 Hi All,I have to bind the pre inserted data to the web page.Page has drop down lists and text boxes.I am using the following methods to bind these controls: 1. Drop down list:                            int index = dropDownList.Items.IndexOf(dropDownList.Items.FindByValue(value));                                 dropDownList.SelectedIndex = ind...

Check if the text box "text" has changed (RePost from web forms forum)
Greetings! How can i know if the "text" inside of a text box has changed? For example, I currently have this: if (txtMU.TextChanged()) { } But this does not work. The other idea I had was to assign the existing value of the text box to a string and then when the user click the save button I can create a conditional statement to compare the original string with the new string. However, I would like something more effective as I have like 12 text boxes to compare. Thanks, EduardoThanks,Please Mark this post as answered if it was helpful. Here is the easiest way that I have ...

Clear text on a text box when user click this box
There is a text box in which has default text "<Please enter your name>". How to clear this text when user click this box? one option might be to use the TextBoxWatermark from the ajax control toolkit http://www.asp.net/ajax/ajaxcontroltoolkit/samples/TextBoxWatermark/TextBoxWatermark.aspxMike Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/ Basic idea:   <input type="text" value="first name" onfocus="if(this.value===this.defaultValue)this.value='&#...

Tabbing through text boxes on a web form
I have 3 text boxes within the body of my html on an asp.net page and when i render the page I am not able to tab from the first box to the next. How do you set this up? Thanks, -=angst=- You can use the TabIndex property of the TextBox object to do this. ex : <asp:TextBox id="myBox1" TabIndex="0" runat="server"/> <asp:TextBox id="myBox2" TabIndex="1" runat="server"/> <asp:TextBox id="myBox3" TabIndex="2" runat="server"/> Make sure each textbox has a un...

Passing Text of a text box in child form to a label in parent form
Hi Elite People !! I have a parent form with a number of ASP Labels and Buttons. Each ASP Label has a ASP Button next to it. What I want to acheive is when you click the button, it should open a new window with a ASP multiline text box and a "save" button. User can enter the text in the text box and when they click the SAve button, the Text in the text box of the Child window should be displayed in the label on the parent form.  I am successfully able to do this when I have a Text Box in the Parent form, but my requirement is to use Labels on the Parent Form. I am ...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Issues with getting selecteditem.text from a web form
I am attempting to make a list box where users can be added to the database. I have created two list boxes and I have managed to transfer the values across. However I am having difficulty in getting the selected index value of the item, which has been selected. I need the selected item to add the user ID of the selected user into the database. Any help would be great. The first part binds the data to the lstproducts listbox the second parts writes data to the database Sub list() Dim Conn As OracleConnection Dim cmdselect As OracleCommand Dim ...

How do you get a class to populate text boxes on a form?
In my class I'm using a data reader to read data: aReader.Read(); string UserID; UserID = (String)aReader.GetValue(0); UserID = (String)aReader.GetValue(1); UserID = (String)aReader.GetValue(2); How do I get the values to txtOne, txtTwo, and txtThree on the form? For example: myTextBox.Text = aReader.GetString(0); The myTextBox is the ID of the TextBox added to a page. When you add a TextBox control on to the page. The specified ID can be used to get access to the control's instance./Fredrik Normén - fredrikn @ twitterMicrosoft MVP, MCSD, MCAD, MCTASPInsidersMy Blog My problem is...

Web resources about - clearing all text boxes on a web form - asp.net.getting-started

Mine-clearing line charge - Wikipedia, the free encyclopedia
A mine-clearing line charge (abbreviated MCLC and pronounced "mick lick") is used to create a breach in minefields under combat conditions. While ...

Social Media Jobs: Wooga, App Minis, Publishers Clearing House
... a new mobile game, as well as an iOS games developer . Meanwhile, App Minis is seeking a senior unity game programmer , and Publishers Clearing ...

Chakra Clearing - Doreen Virtue, Ph.D. on the App Store on iTunes
Get Chakra Clearing - Doreen Virtue, Ph.D. on the App Store. See screenshots and ratings, and read customer reviews.

Clearing Skies at Target Field - Flickr - Photo Sharing!
A little rain in the bottom of the first gave way to a perfect night for baseball at Target Field.

Excavator mulchers - Land clearing equipment - Forestry mulcher - DENISCIMAF.com - YouTube
Land clearing equipment, forestry mulcher for excavators. These excavator mulchers are ideal for intensive vegetation control, land clearing, ...

Houston eyes future benefits after clearing out veterans
Houston eyes future benefits after clearing out veterans

Labor says trade union royal commission submissions clearing Bill Shorten released at ‘odd’ time - AdelaideNow ...
OPPOSITION Leader Bill Shorten says he is pleased to be cleared of any wrongdoing during his time as boss of the Victorian branch of the Australian ...

10/50 tree-clearing rule: misuses flagged by two councils before 1000 trees removed
Misuses of the 10/50 rule - allowing property owners in fire-prone areas to remove trees without permission - were flagged by two Sydney councils ...

Two sides to the clearing debate
While ASX chief executive Elmer Funke Kupper argues that offshore clearing of derivatives transactions could lead to systemic risk, increased ...

Puneet Puneet refused bail in India, clearing way for extradition to Australia
... resulted in a student's death. India’s highest court on Tuesday rejected a bail application by fugitive hit-and-run driver Puneet Puneet, clearing ...

Resources last updated: 12/12/2015 4:05:01 AM