Help with custom button server control

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("&nbsp;")
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top