ASP.NET Custom Server Controls: Combining ImageHoverButton and RoundCorneredButton - How did I handle the post backs?
(Page 7 of 8 )
Another extension to the same control is the following code fragment. Take a look at 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 would 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 “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 deals with the concepts of both eventing and delegating. The above statements made it possible to implement ‘postback’ing together with delegating. I suggest you to go through OOPS in .NET, if you are not familiar with Events and Delegates.
Next: How is it different from my previous controls? >>
More ASP.NET Articles
More By Jagadish Chaterjee