I have made custom button control, but I'm missing something because I can't get it work properly.
Button works if render method is like this:
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
But when I change code to this:
protected override void Render(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Class, css);
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID);
writer.AddAttribute(HtmlTextWriterAttribute.Name, this.ID);
writer.RenderBeginTag(HtmlTextWriterTag.Button);
writer.RenderBeginTag(Html开发者_开发技巧TextWriterTag.Span);
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.Write(base.Text);
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderEndTag();
}
It just loads same page where button was clicked and nothing else happens.
So what I'm not doing what base.Render(write) does? And is there anything else in these custom control buttons what should be done or can I do this better?
Buttons output should be something like:
<button>
<span>
<span>
<span>
Title
</span>
</span>
</span>
</button>
You should invoke the base method...
base.Render(writer);
Like below ↓
protected override void Render(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Class, css);
writer.AddAttribute(HtmlTextWriterAttribute.Id, this.UniqueID);
writer.AddAttribute(HtmlTextWriterAttribute.Name, this.ID);
writer.RenderBeginTag(HtmlTextWriterTag.Button);
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.RenderBeginTag(HtmlTextWriterTag.Span);
writer.Write(base.Text);
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderEndTag();
writer.RenderEndTag();
base.Render(writer);
}
精彩评论