PDA

View Full Version : programmatically change borderstyle on control


KPayne
01-18-2004, 02:16 AM
Carl,

You can use s.BorderStyle.ToString() instead of s.ID.BorderStyle.Solid to display the value of the BorderStyle property.

Try this code:
[quote]
SubDisplayControls(ByValsAsObject)
DimctlControlAsWebControl
DimProps()AsSystem.Reflection.PropertyInfo=ctlCont rol.GetType.GetProperties_
(Reflection.BindingFlags.InstanceOrReflection.Bind ingFlags.Public)
DimtempPropAsSystem.Reflection.PropertyInfo
DimHasBorderStylePropertyAsBoolean

ForEachtempPropInProps
IftempProp.Name="BorderStyle"Then
HasBorderStyleProperty=True
ExitFor
EndIf
Next

IfHasBorderStylePropertyThen
ForEachctlControlIns.Controls
DisplayControlInfo(ctlControl)
DisplayControls(ctlControl)
ctlControl.BorderStyle=BorderStyle.Solid
DisplayControls(ctlControl)
Next
EndIf
EndSub

SubDisplayControlInfo(ByValsAsObject)
Response.Write(CType(s,WebControl).ID&"&nbsp"&_
CType(s,TextBox).BorderStyle.ToString())
EndSub
</CODE>

Keith Payne
Technical Marketing Solutions

nature
01-18-2004, 08:19 AM
I want to apply a server style to all controls on a page. Instead of applying the style to each one individually - txtTextBox1.borderstyle = "solid"
I want to loop thru the controls and apply the style.
I tried this and s.id is just a string. What do I do to access the controls properties?
Sub DisplayControls( s As Object )
Dim ctlControl As Control

For Each ctlControl in s.Controls
DisplayControlInfo( ctlControl )
strControlList &= "<ul>"
DisplayControls( ctlControl )
strControlList &= "</ul>"
Next
End Sub

Sub DisplayControlInfo( s As Object )
s.ID.BorderStyle.Solid
End Sub

Thanks for your help! Carl