Reputation: 2533
I built a custom control for all my applications that would render menu taking name of the respective application and logged in user roles and render the menus accordingly. I am using an already written javascript for rendering menu that is loaded from db in the form of html string containing divs and unordered lists. Now, coming to the original problem, previously I inherited my control with Panel class, which is rendered as div in html, I just wrote the generated HTML in the inherited panel container. Now, I want to integrate the control with the websites that already have sitemaps. For that, I inherited my control from Menu class and now I am confused how to render the menu html. The code of how I was rendering it previously is pasted below.
[DefaultProperty("Text")]
[ToolboxData(@"<{0}:MenuControl runat=""server"" \>")]
public class MenuControl : Panel
{
.
.
.
.
.
#region Loading Resources On PreRender
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (string.IsNullOrEmpty(this.DataSourceID))
{
ClientScriptManager cs = this.Page.ClientScript;
#region Loading JavaScript File(s)
#endregion
#region Loading CSS File(s)
#endregion
#region Loading Image(s)
#endregion
}
}
#endregion
#region Rendering Final Contents
protected override void RenderContents(HtmlTextWriter output)
{
string Menus = string.Empty;
//Where as Menus contain menu in an html structure of ordered list.
Menus = GetMenuForAppOnUser();
output.Write(Menus);
}
#endregion
.
.
.
.
}
Now, as it was inherited with Panel, so I just had to write some html inside the inherited panel(div). How do I now write menuhtml when it is inherit from Menu class.
Upvotes: 0
Views: 105
Reputation: 2533
Found out the solution, for Menu, Render actually renders the control instead of RenderContents as for Panel.
#region Rendering Final Contents
protected override void Render(HtmlTextWriter output)
{
string Menus = string.Empty;
//Where as Menus contain menu in an html structure of ordered list.
Menus = GetMenuForAppOnUser();
output.Write(Menus);
}
#endregion
Upvotes: 0