Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Iterate web form textboxes in codebehind page
Message
 
To
30/09/2003 08:18:55
Jacci Adams
Lindsay-Adams Consulting
Louisville, Ohio, United States
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00833414
Message ID:
00833552
Views:
22
Hi Jacci,

There is sample code about iterating through controls in the Feb. 2003 .NET tips. It is the box in the lower left side. Here is the link:

http://www.utmag.com/February2003/Page3.asp


>Hi All,
>
>I need to iterate through all of the controls on my web form to look for the textboxes and pass their contents to a 3rd party spell checker. I can't seem to find the correct methods to do this or a good example of how to do this. I'm still trying to figure out the object hierarchy.
>
>Below is what I have so far:
>
>'---------------------------------------------------------------
> Dim intControl, intCurrentControl As Int32
> Dim FormItems As Collection
> Dim strContents, strControlName, strTextBoxValue As String
> Dim ControlItem As New Control
> Dim myTextBox As New TextBox
> Dim myspellchecker As Com.Keyoti.RapidSpell.RapidSpellChecker
>
>
> intControl = 0
> For Each ControlItem In Me.Page.Controls
>
> strControlName = ControlItem.ID.ToUpper
> If strControlName.Substring(1, 4) = "TEXT" Then
> '--this control is a textbox spell check it's contents.
> myTextBox = ControlItem.FindControl(strControlName)
> strTextBoxValue = myTextBox.Text
> myspellchecker.Check(strTextBoxValue)
> End If
>
> intControl += 1
>
> Next
>
>'-----------------------------------------
>
>I keep getting this error:
>Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
>
>on this statement:
>strControlName = ControlItem.ID.ToUpper
>
>BTW, what's the syntax for creating code blocks in these messages?
>
>I also need some clarification as to when to initialize variables as a "New" type.
>
>TIA,
>Jacci
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform