I've got a simple user control in my ASP.NET Webforms project which inherits from the LinkButton. It's got a property to change the size, which just adds some predefined CSS classes to the control.
Protected Overrides Sub CreateChildControls()
Dim SizeClass As String = String.Empty
If Size = SizeEnum.Large Then
SizeClass = "large"
Else
SizeClass = "small"
End If
Me.CssClass += " button " + SizeClass
Me.Controls.Add(New LiteralControl(String.Format("<span class=""l"">{0}</span><span class=""r""></span><span class=""clear""></span>", Me.Text)))
MyBase.CreateChildControls()
End Sub
Pretty simple, right? So when it renders the class property is something like class="button small"
.
When this control is placed inside an update panel along with some other things, when the update panel updates the class property for every one of these controls becomes class=" button small button开发者_如何学Go small button small button small button small button small button small button small button small button small button small button small button small"
Which is a little bit rediculous. Any idea on why this is happening?
Try changing
Me.CssClass += " button " + SizeClass
to
Me.CssClass = " button " + SizeClass
Each time the control renders, the CssClass is stored in ViewState of the control. So when it renders it keeps appending.
精彩评论