ASP.NET Custom Server Controls: Dynamically Expandable Round Cornered Button - Starting with Table
(Page 3 of 7 )
The default “Render” method (when not overridden by us) usually calls the “RenderBeginTag” before calling any other methods. Let us examine the “RenderBeginTag” method in my control step by step:
MyBase.AddAttributesToRender (writer)
writer.AddAttribute(HtmlTextWriterAttribute.Border,
"0px")
writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding,
"0px")
writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing,
"0px")
writer.AddStyleAttribute("text-Align", "center")
writer.AddStyleAttribute("vertical-Align", "middle")
writer.AddAttribute(HtmlTextWriterAttribute.Onclick,
Page.GetPostBackEventReference(Me, String.Empty))
writer.AddStyleAttribute("cursor", "hand")
writer.RenderBeginTag(HtmlTextWriterTag.Table)
Within the above method, I am trying to call the “MyBase.AddAttributesToRender(Writer)” statement to add any design-time attributes to my control. This is a must when we use the control with the Visual Studio.NET designer. You can also override with any other attributes you want (as shown in my previous articles of the same series). From all the above statements, the conclusion would be something like this: I am trying to render a “<TABLE>” tag with some attributes. Note that the tags have not yet been closed!
One of the most important statements to focus on from the above is:
writer.AddAttribute(HtmlTextWriterAttribute.Onclick,
Page.GetPostBackEventReference(Me, String.Empty))
That is the main trick I played to convert the “table” to “button.” Once the above statement is executed, it now supports a post back when clicked!
Starting simply with “<TABLE>” is not enough. We need to frame a 3x3 set of cells within the table. I call the first row of cells the header, second row of cells the body (or content) and third row the footer for better understanding.
In our next section, we shall see how to implement the header.
Next: Creating the header >>
More ASP.NET Articles
More By Jagadish Chaterjee