ASP.NET Custom Server Controls: Round Cornered box control in ASP.NET - Exposing properties for every side (including corners) of the box
(Page 2 of 5 )
As you know, every side of the box needs to be provided with some image (including the corners, of course). The following are the properties which handle all of those images (paths of those images).
Property ImageTopLeftURL() As String
Property ImageTopMiddleURL() As String
Property ImageTopRightURL() As String
Property ImageMiddleLeftURL() As String
Property ImageMiddleMiddleURL() As String
Property ImageMiddleRightURL() As String
Property ImageBottomLeftURL() As String
Property ImageBottomMiddleURL() As String
Property ImageBottomRightURL() As String
I hope all of the above are simple to read and understandable. I declared each of those properties with an attribute at the top as follows:
<EditorAttribute(GetType (System.Web.UI.Design.UrlEditor),GetType
(System.Drawing.Design.UITypeEditor))>
The above is the most exciting statement used with all the previous properties. The “EditorAttribute” is mainly helpful for the Visual Studio.NET designer to facilitate an editor for the value being provided to that property (similar to the “Font” property).
In this case, we attach a dialog box (Visual Studio.NET supported open dialog) to the property, to facilitate the developer in selecting a respective image from folders within the web application hierarchy. If we don’t specify the above attribute, the developer needs to remember and type the entire path of the image within the property window of Visual Studio.NET designer, as opposed to simply selecting the image file.
Starting with <TABLE>
The default “Render” method (when not overridden by us) usually calls “RenderBeginTag” before calling any other methods. Let us examine the “RenderBeginTag” method in my control step by step:
MyBase.AddAttributesToRender (writer)
writer.AddAttribute (HtmlTextWriterAttribute.Name,
Me.UniqueID)
writer.AddAttribute (HtmlTextWriterAttribute.Id,
Me.ClientID)
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.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: I am trying to render a “<TABLE>” tag with some attributes. Please note that the tags have not yet been closed!
Starting simply with “<TABLE>” is not enough. We need to frame 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