ASP.NET Custom Server Controls: Dynamically Expandable Round Cornered Button - How did I handle the postbacks?
(Page 7 of 7 )
Another extension to the same control is the following code fragment. Try obrserving it.
Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
If Not Page Is Nothing Then
Page.VerifyRenderingInServerForm(Me)
End If
MyBase.Render(writer)
End Sub
The above implementation of the “Render” method ensures that the placement of your control should be within the “<FORM>” tag itself. It will automatically raise an error if not placed within the “<FORM>” tag. You should also observe the second statement, “MyBase.Render(writer)”. It asks to proceed with rendering as usual without considering any other issue.
The next question would be, how did I implement the “OnClick” event within my control? The following statements at various locations made it possible:
Public Event Click As EventHandler
Public Sub RaisePostBackEvent(ByVal eventArgument As String)
Implements System.Web.UI.IPostBackEventHandler.RaisePostBackEvent
OnClick(EventArgs.Empty)
End Sub
Protected Overridable Sub OnClick(ByVal e As EventArgs)
RaiseEvent Click(Me, e)
End Sub
It is the concept of both eventing and delegating. The above statements made it possible to implement ‘postback’ing together with delegating. I suggest you go through OOPS in .NET, if you are not familiar with events and delegates.
Even though I started emitting exclusive HTML using “writer” methods, you can also do the same by extending your control from an already existing “table” web control. If you directly extend it from a “table” web control, you can work with an almost .NET based ASP.NET framework model to add table rows and cells, which looks convenient and even readable. But then we need to understand a bit about the “rendering” issues of child controls within the parent control.
I leave it to the developers to further enhance the same control. The areas of improving the same control would include eventing, JavaScript for mouse hovers, data-binding, and so forth. Good luck.
Any comments, suggestions, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.