Fast way to loop thru all controls on a webpage (VB.NET 2.0)

Last post 08-21-2008 11:30 PM by vinz. 4 replies.

Sort Posts:

  • Fast way to loop thru all controls on a webpage (VB.NET 2.0)

    01-24-2007, 9:43 AM
    • Member
      point Member
    • DennisBetten
    • Member since 01-23-2007, 3:18 PM
    • Posts 2
    The following code allows you to easilly loop thru all webpage controls and change their settings. For example change all ToolTips of the existing Textboxes:
     
     
    Code into PageLoad:
     
    Dim strToolTip = "HELP"
    FindToolTipControl(Page.Controls, strToolTip)       ' or: FindToolTipControl(mainTable.Controls, strToolTip) or whatever controcolection you would like to loop thru
     
     
    The functions:
     
    Private Sub FindToolTipControl(ByVal oControlCollection As ControlCollection, ByVal strToolTip As String)
            For Each oControl As Control In oControlCollection
                SetTooltip(oControl, strToolTip)
                FindToolTipControl(oControl.Controls, strToolTip)
            Next
        End Sub
        Private Sub SetTooltip(ByVal oControl As Control, ByVal strToolTip As String)
            Select Case oControl.GetType.ToString
                Case "System.Web.UI.WebControls.TextBox"
                    Dim otxt As TextBox = oControl.FindControl(oControl.ID)
                    otxt.ToolTip = strToolTip
                Case "System.Web.UI.WebControls.RadioButton"
                    Dim otxt As RadioButton = oControl.FindControl(oControl.ID)
                    otxt.ToolTip = strToolTip
                Case "System.Web.UI.WebControls.CheckBox"
                    Dim otxt As CheckBox = oControl.FindControl(oControl.ID)
                    otxt.ToolTip = strToolTip
                Case "System.Web.UI.WebControls.FileUpload"
                    Dim otxt As FileUpload = oControl.FindControl(oControl.ID)
                    otxt.ToolTip = strToolTip
            End Select
        End Sub
     
     
    You can apply this code to any page you want or, if you use a masterpage, just paste it in the codebehind of the masterpage!
    (most settings to controls can also be set in skin-files or with css, but that takes to much time in my opinion)
     
    Enjoy!
  • Re: Fast way to loop thru all controls on a webpage (VB.NET 2.0)

    01-25-2007, 11:51 PM
    Answer

    hi DennisBetten

    Really thanks so much for sharing your good idea and code with us!

    It is a perfect tip!

    Thanks again!

    Jessica

    Jessica Cao
    Sincerely,
    Microsoft Online Community Support


    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • Re: Fast way to loop thru all controls on a webpage (VB.NET 2.0)

    03-04-2007, 1:21 AM
    • Member
      4 point Member
    • mahnaz
    • Member since 03-04-2007, 6:17 AM
    • Posts 9

    Hi ,

    thank you for sharing .

  • Re: Fast way to loop thru all controls on a webpage (VB.NET 2.0)

    08-21-2008, 11:15 PM
    • Member
      155 point Member
    • bluelabs
    • Member since 02-23-2004, 11:39 AM
    • Montreal
    • Posts 43

    Hi

    Nice post thanks

    I have one problem

    How I can setup ToolTip in Asian langs for windows XP?

    example

    <asp:TextBox ID="TextBox1" runat="server">

    </asp:TextBox><asp:RequiredFieldValidator ControlToValidate="TextBox1" ID="RequiredFieldValidator1" runat="server" ErrorMessage="setup from App_GlobalResources NO PROBLEM PREVIEW OK" ToolTip="...same setup PROBLEM!!!!!"></asp:RequiredFieldValidator>

    thanks

    val

    I found one solution

     

    Control Panel > Display Properties > Appearance > Item: ToolTip : set to
    Arial Unicode MS

     

    Thanks
    Valentin

    http://www.montrealads.ca
    http://www.whoiswho.ca
    http://www.bluelabs.ca
  • Re: Fast way to loop thru all controls on a webpage (VB.NET 2.0)

    08-21-2008, 11:30 PM
    • All-Star
      91,668 point All-Star
    • vinz
    • Member since 10-05-2007, 11:47 AM
    • Cebu, Philippines
    • Posts 13,769
    • TrustedFriends-MVPs

    Great idea mate! But i think this thread should be placed at the Tips & Tricks section of this site.

    "Code,Beer and Music ~ my way of being a programmer"

Page 1 of 1 (5 items)
Microsoft Communities