Hi
I have a nice set of html and now I need to use RenderBeginTag, RenderEndTag 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.
Hi
I have a nice set of html and now I need to use RenderBeginTag, RenderEndTag 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.
Hi there.
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.
Cheers. Jas.
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>")] 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);
}
}
}