我已经进行了自定义按钮控制,但我遗漏了一些东西,因为我无法正常工作。
如果渲染方法如下,则按钮有效:
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
}
但是当我改变代码时:
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(写)呢?这些自定义控制按钮还有什么应该做的或者我能做得更好吗?
按钮输出应该是这样的:
<button>
<span>
<span>
<span>
Title
</span>
</span>
</span>
</button>
答案 0 :(得分:1)
你应该调用基本方法......
base.Render(writer);
如下↓
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);
}