ASP.NET Custom Server Controls: Combining ImageHoverButton and RoundCorneredButton - Closing the body (content) and creating the footer
(Page 6 of 8 )
In the previous section, we already opened the center cell. But we didn’t close yet. In this section we are going to close it.
writer.RenderEndTag() 'td
'middle right
writer.AddAttribute(HtmlTextWriterAttribute.Width, "0px")
writer.AddAttribute(HtmlTextWriterAttribute.Height,
"0px")
writer.AddAttribute(HtmlTextWriterAttribute.Id, Me.ClientID & "_td_MiddleRight")
If Me.ImageMiddleRightURL.Trim.Length > 0 Then
writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundImage, "url(" &
Me.ImageMiddleRightURL.Trim & ")")
writer.AddStyleAttribute("background-repeat",
"repeat-y")
End If
writer.RenderBeginTag(HtmlTextWriterTag.Td)
writer.RenderEndTag() 'td
writer.RenderEndTag() 'tr
The above is quite straightforward for closing the previously opened “<TD>” tag. But the above code is not part of the “RenderBeginTag” method. Instead, it is from the “RenderEndTag” method. We further proceed to create the footer row by adding the same type of code (with very few modifications) available in “Creating the Header” section to the above code fragment. As the coding is quite similar, you can get it from the downloadable.
Everything until now is quite okay. How did I implement the trick to get the “developer specified content” into my control? This is from the following code fragment.
Protected Overrides Sub RenderContents(ByVal writer As
System.Web.UI.HtmlTextWriter)
writer.Write(" " & Text)
End Sub
Even though it is only three lines, it should be considered the heart of the control. In other words, when the control is getting rendered, it first executes the “RenderBeginTag” method followed by the “RenderContents” method and finally “RenderEndTag”. I added a space “ ” just to maintain some gap after the icon. For a detailed explanation of “rendering” issues, I suggest you to refer to my previous articles in the same series.
Next: How did I handle the post backs? >>
More ASP.NET Articles
More By Jagadish Chaterjee