How to Generate Server-Side tags dynamiclly

Posted by Nasser Hajloo on Stack Overflow See other posts from Stack Overflow or by Nasser Hajloo
Published on 2010-04-19T08:24:23Z Indexed on 2010/04/19 8:33 UTC
Read the original article Hit count: 548

Filed under:
|
|
|

I have an ASP.net page which contains some controls.

I generate this controls by code, [Actually I have a method which uses a stringBuilder and add Serverside tag as flat string on it]

My page shows the content correctly but unfortunately my controls became like a Client-side control

For example I had a LoginView on my generated code which dosen't work, and also I had read some string from LocalResources which dosen't appear on the page

What Should I do to make my generating method correct

here is the code

protected string CreateSubSystem(string id, string roles, string AnonymousTemplateClass, string href, string rolesContentTemplateClass, string LoggedInTemplateClass)
{
    StringBuilder sb = new StringBuilder();
    sb.Append("<div class=\"SubSystemIconPlacement\" id=\"");
    sb.Append(id);
    sb.Append("\"><asp:LoginView runat=\"server\" ID=\"");
    sb.Append(id);
    sb.Append("\"><AnonymousTemplate><div class=\"");
    sb.Append(AnonymousTemplateClass);
    sb.Append("\"></div><asp:Label ID=\"lblDisabled");
    sb.Append(id);
    sb.Append("\" runat=\"server\" SkinID=\"OneColLabel\" meta:resourcekey=\"lbl");
    sb.Append(id);
    sb.Append("\" /></AnonymousTemplate><RoleGroups><asp:RoleGroup Roles=\"");
    sb.Append(roles);
    sb.Append("\"><ContentTemplate><a class=\"ImageLink\" href=\"");
    sb.Append(href);
    sb.Append("\"><div class=\"");
    sb.Append(rolesContentTemplateClass);
    sb.Append("\"></div></a><asp:HyperLink runat=\"server\" CssClass=\"SubSystemText\" ID=\"lnk");
    sb.Append(id);
    sb.Append(" NavigateUrl=\"~/");
    sb.Append(href);
    sb.Append(" \" meta:resourcekey=\"lbl");
    sb.Append(id);
    sb.Append("\" /></ContentTemplate></asp:RoleGroup></RoleGroups><LoggedInTemplate><div class=\"");
    sb.Append(LoggedInTemplateClass);
    sb.Append("\"></div><asp:Label runat=\"server\" SkinID=\"OneColLabel\" ID=\"lblDisabledLoggedIn");
    sb.Append(id);
    sb.Append("\" meta:resourcekey=\"lbl");
    sb.Append(id);
    sb.Append("\" /></LoggedInTemplate></asp:LoginView>");
    sb.Append("</div>");
    return sb.ToString();
}

I also use this method on page_PreRender event

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#