<div>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:</div> <div> </div> <div> </div> <div>Code into PageLoad:</div> <div> </div> <div>Dim strToolTip
= "HELP"
FindToolTipControl(Page.Controls, strToolTip) ' or: FindToolTipControl(mainTable.Controls, strToolTip) or whatever controcolection you would like to loop thru</div> <div> </div> <div> </div> <div>The functions:</div> <div> </div> <div>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</div> <div> 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</div> <div> </div> <div> </div> <div>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!</div> <div>(most settings to controls can also be set in skin-files or
with css, but that takes to much time in my opinion)</div> <div> </div> <div>Enjoy!</div>
Web ControlsMaster PagesASP.NET 2.0MasterPagesPage.FindControlFindControlASP.NET 2.0 VB.NETControlparametermasterpage usercontrol.netcontrols
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. ”
DennisBetten
0 Points
2 Posts
Fast way to loop thru all controls on a webpage (VB.NET 2.0)
Jan 24, 2007 01:43 PM|LINK
FindToolTipControl(Page.Controls, strToolTip) ' or: FindToolTipControl(mainTable.Controls, strToolTip) or whatever controcolection you would like to loop thru</div> <div> </div> <div> </div> <div>The functions:</div> <div> </div> <div>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</div> <div> 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</div> <div> </div> <div> </div> <div>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!</div> <div>(most settings to controls can also be set in skin-files or with css, but that takes to much time in my opinion)</div> <div> </div> <div>Enjoy!</div>
Web Controls Master Pages ASP.NET 2.0 MasterPages Page.FindControl FindControl ASP.NET 2.0 VB.NET Controlparameter masterpage usercontrol .net controls
Jessica Cao ...
All-Star
25328 Points
2567 Posts
Re: Fast way to loop thru all controls on a webpage (VB.NET 2.0)
Jan 26, 2007 03:51 AM|LINK
hi DennisBetten
Really thanks so much for sharing your good idea and code with us!
It is a perfect tip!
Thanks again!
Jessica
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. ”
mahnaz
Member
4 Points
9 Posts
Re: Fast way to loop thru all controls on a webpage (VB.NET 2.0)
Mar 04, 2007 05:21 AM|LINK
Hi ,
thank you for sharing .
bluelabs
Member
157 Points
44 Posts
Re: Fast way to loop thru all controls on a webpage (VB.NET 2.0)
Aug 22, 2008 03:15 AM|LINK
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.whoiswho.ca
http://www.bluelabs.ca
vinz
All-Star
127011 Points
17934 Posts
MVP
Re: Fast way to loop thru all controls on a webpage (VB.NET 2.0)
Aug 22, 2008 03:30 AM|LINK
Great idea mate! But i think this thread should be placed at the Tips & Tricks section of this site.
MessageBox Controls for WebForms | Blog | Twitter | Linkedin