A couple people have requested the source code for the ServerConfirm button I wrote. This adds a yes-no MessageBox to a regular html button. Clicking either yes or no triggers the appropriate server event.
Note that I wrote this version over a year ago, and there are some changes I would make:
The JavaScript used to get the selected MessageBox value doesn't work in NN.
This is a custom-rendered control, which is created entirely from scratch - i.e. just html controls. It could be made as an extended control instead. This would still be compiled to a DLL and be reusable among ASP.Net projects (unlike UserControls), but would give the additional advantage of keeping all the WebControl.Button's extra properties that merely the Html button lacks.
I'll cover these in a future blog post. FYI, other blog posts related to this are:
Set(ByVal Value AsString) _strMessage = Value EndSet EndProperty
#End Region
ProtectedOverridesSub Render(ByVal output As System.Web.UI.HtmlTextWriter) 'output.Write([Text])
Dim strHdnName AsString = Me.UniqueID
'generate hidden field to store answer: ' output.WriteBeginTag("Input") output.WriteAttribute("type", "hidden") output.WriteAttribute("name", strHdnName) output.WriteAttribute("value", "none") output.Write(HtmlTextWriter.TagRightChar)
PublicFunction LoadPostData(ByVal postDataKey AsString, ByVal postCollection As System.Collections.Specialized.NameValueCollection) AsBooleanImplements System.Web.UI.IPostBackDataHandler.LoadPostData
'Note: a field with Me.UniqueID must be declared for this to fire. 'Get the hidden field value so we know which event to trigger If (postCollection(postDataKey).Equals("Yes")) Then _blnConfirm = True Else _blnConfirm = False EndIf
EndFunction
PublicSub RaisePostDataChangedEvent() Implements System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent 'Get the hidden field value so we know which event to trigger EndSub
#End Region
#Region"PostBack Events"
PublicSub RaisePostBackEvent(ByVal eventArgument AsString) Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent 'check the hidden field to determine which event to raise. If (_blnConfirm) Then OnConfirmYes(EventArgs.Empty) Else OnConfirmNo(EventArgs.Empty) EndIf EndSub
Event ConfirmYes(ByVal sender AsObject, ByVal e As EventArgs)
ProtectedOverridableSub OnConfirmYes(ByVal e As EventArgs) 'raise the event RaiseEvent ConfirmYes(Me, EventArgs.Empty) EndSub
Event ConfirmNo(ByVal sender AsObject, ByVal e As EventArgs)
ProtectedOverridableSub OnConfirmNo(ByVal e As EventArgs) RaiseEvent ConfirmNo(Me, EventArgs.Empty) EndSub
No comments:
Post a Comment