How to generate html output of some control by API

HelenaG Grulichova asked on March 26, 2012 09:10

How to generate html output of some control by API

Correct Answer

HelenaG Grulichova answered on March 26, 2012 09:10

In special cases you may need to generate html code and provide it as a web service. The example shows how to create a repeater control dynamically, configure its properties and return html code.

  [WebMethod]
    public static string GetDate()
    {
        Page pageHolder = new Page();

        CMSRepeater rep = (CMSRepeater)pageHolder.LoadControl(typeof(CMSRepeater), null);
        rep.ClassNames = "cms.article";
        rep.Path = ".";
        rep.TransformationName = "cms.article.default";

        pageHolder.Controls.Add(rep);

        StringWriter output = new StringWriter();
        HttpContext.Current.Server.Execute(pageHolder, output, false);

        return output.ToString();
    }
-it-
0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.