Ok,
I see. You can inherit from Button but it needs a bit different approach. Hhere's basic skeleton for you. It has a Button which registers a hidden field using Page.ClientScript.RegisterHiddenField and demonstrates how to keep up the hidden field value within postbacks in this case. It also exposes the hidden field value out as a property.
You need to add yourself the client-script related stuff as well as otherwise maybe modify it.
Imports Microsoft.VisualBasic
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class MyButton
Inherits Button
Implements IPostBackDataHandler
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
MyBase.OnPreRender(e)
'Registering the hidden field for every request
If Not Me.Page Is Nothing Then
Page.ClientScript.RegisterHiddenField(HiddenClientID, HiddenValue)
End If
End Sub
'Property to keep hidden field value in View state of the control
Public Property HiddenValue() As String
Get
Return CStr(ViewState("HiddenValue"))
End Get
Set(ByVal value As String)
ViewState("HiddenValue") = value
End Set
End Property
'ID which is used to register the hidden field as well as read its value
Protected ReadOnly Property HiddenClientID() As String
Get
Return Me.ClientID & "_hidden"
End Get
End Property
'Participating to the postback processing so that we can take the posted hidden field value
Public Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NameValueCollection) As Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData
Dim value As String = postCollection(HiddenClientID)
HiddenValue = value
'Because implementing both IPostBAckDataHandler and IPostBackEventHandler (Button does)
'needs to call this so that postback event will be raised normally
If Not postCollection(Me.UniqueID) Is Nothing Then
Page.RegisterRequiresRaiseEvent(Me)
End If
Return False
End Function
Public Sub RaisePostDataChangedEvent() Implements System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent
'Not in use, but gotta implement because of the interface
End Sub
End Class
Thanks,
Teemu Keiski
Finland, EU