开发者

How to convert html to ASP.Net write.RenderBeginTag type code

I have a nice set of html and now I need to use RenderBeginTag, R开发者_开发知识库enderEndTag type of code in my custom control render method. Is there any tools for converting html C# code? It's just too much work for nothing, if I start coding this manually.


When writing custom WebControl classes, you can still use standard ASP.NET controls, avoiding the need to use the tag rendering methods:

[ToolboxData("<{0}:MyCustomControl runat=server></{0}:MyCustomControl>")]
public class MyCustomControl : CompositeControl
{
    public MyCustomControl()
    {

    }

    public string Text
    {
        get
        {
            object o = ViewState["Text"];
            return ((o == null) ? "Set my text!" : (string)o);
        }
        set
        {
            ViewState["Text"] = value;
        }
    }

    protected override void CreateChildControls()
    {
        // Create controls
        var label = new Label();
        label.ID = "innerLabel";
        label.Text = this.Text;

        // Add controls
        this.Controls.Add(label);

        // Call base method
        base.CreateChildControls();
    }
}

Or you can use the tags in the render methods like so:

[ToolboxData("<{0}:MyCustomControl runat=server></{0}:MyCustomControl>")]
public class MyCustomControl : CompositeControl
{
    public MyCustomControl()
    {

    }

    public override void RenderControl(HtmlTextWriter writer)
    {
        base.RenderEndTag(writer);

        if (!this.DesignMode)
        {
            var label = new Label();
            label.Text = "Hello!";
            label.RenderControl(writer);
        }
    }
}

Hopefully this answers your question :s


[ToolboxData("<{0}:MyCustomControl runat=server></{0}:MyCustomControl>")]
public class MyCustomControl : CompositeControl
{
    public MyCustomControl()
    {

    }

    public override void RenderControl(HtmlTextWriter writer)
    {
        base.RenderEndTag(writer);

        if (!this.DesignMode)
        {
            var label = new Label();
            label.Text = "Hello!";
            label.RenderControl(writer);
        }
    }
}


I'm not sure there is a way to do this. The closest I could find was this site which generates HTML code into Response.Write calls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜