L
lisa
I'm trying to make a version of the button server control that renders
as a <button> tag, rather than an <input type=button> tag.
It seemed fairly simple, but I've run into three snags:
1) AddAttributesToRender doesn't seem to be adding any
attributes to the render.
2) I can't resize the control in design time
3) Strangest of all, if I put one of these on a page,
followed immediately by a regular button, the regular
button winds up with all the attributes that should
have been in the custom button. The custom button
still has no attributes at all.
Here's the code. Can anyone point out what I'm doing wrong, please?
Thanks,
Lisa
Imports System.ComponentModel.Design
Imports System.ComponentModel
Imports System.Web.UI
<DefaultProperty("Text"), Description("TMButton allows the text
attribute to contain HTML"), ToolboxData("<{0}:TMButton
runat=server></{0}:TMButton>"), Designer(GetType(TMButtonDesigner))> _
Public Class TMButton
Inherits System.Web.UI.WebControls.Button
Public Sub New()
Me.Text = "Button"
End Sub 'New
Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
writer.WriteBeginTag("button")
Me.AddAttributesToRender(writer)
writer.Write(">")
If Me.Text Is Nothing Or Me.Text = "" Then
writer.Write(" ")
Else
writer.Write(Me.Text)
End If
writer.WriteEndTag("button")
End Sub 'Render
End Class 'TMButton
Public Class TMButtonDesigner
Inherits System.Web.UI.Design.ControlDesigner
Private _allowresize As Boolean
Public Sub New()
Me.AllowResize = True
End Sub 'New
'For some reason, the custom control defaults to ReadOnly
AllowResize=False.
'So we shadow it to allow resizing (because a regular button can be
resized).
Public Shadows Property AllowResize() As Boolean
Get
Return _allowresize
End Get
Set(ByVal Value As Boolean)
_allowresize = Value
End Set
End Property 'AllowResize
End Class 'TMButtonDesigner
as a <button> tag, rather than an <input type=button> tag.
It seemed fairly simple, but I've run into three snags:
1) AddAttributesToRender doesn't seem to be adding any
attributes to the render.
2) I can't resize the control in design time
3) Strangest of all, if I put one of these on a page,
followed immediately by a regular button, the regular
button winds up with all the attributes that should
have been in the custom button. The custom button
still has no attributes at all.
Here's the code. Can anyone point out what I'm doing wrong, please?
Thanks,
Lisa
Imports System.ComponentModel.Design
Imports System.ComponentModel
Imports System.Web.UI
<DefaultProperty("Text"), Description("TMButton allows the text
attribute to contain HTML"), ToolboxData("<{0}:TMButton
runat=server></{0}:TMButton>"), Designer(GetType(TMButtonDesigner))> _
Public Class TMButton
Inherits System.Web.UI.WebControls.Button
Public Sub New()
Me.Text = "Button"
End Sub 'New
Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
writer.WriteBeginTag("button")
Me.AddAttributesToRender(writer)
writer.Write(">")
If Me.Text Is Nothing Or Me.Text = "" Then
writer.Write(" ")
Else
writer.Write(Me.Text)
End If
writer.WriteEndTag("button")
End Sub 'Render
End Class 'TMButton
Public Class TMButtonDesigner
Inherits System.Web.UI.Design.ControlDesigner
Private _allowresize As Boolean
Public Sub New()
Me.AllowResize = True
End Sub 'New
'For some reason, the custom control defaults to ReadOnly
AllowResize=False.
'So we shadow it to allow resizing (because a regular button can be
resized).
Public Shadows Property AllowResize() As Boolean
Get
Return _allowresize
End Get
Set(ByVal Value As Boolean)
_allowresize = Value
End Set
End Property 'AllowResize
End Class 'TMButtonDesigner