我尝试使用波纹管代码创建自定义图像按钮,但我仍然无法在单击图像时触发单击事件。请问有人可以帮我吗?
DefaultProperty("Text"),
ToolboxData("<{0}:CustomButton runat=\"server\"> </{0}:CustomButton>")
]
[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public class CustomButton : Button
{
private string imgURL;
#region Constructor
public CustomButton() { }
#endregion
#region Properties
[Bindable(true)]
[Category("Appearance")]
[Description("ShowImage")]
[DefaultValue(false)]
public bool ShowImage { get; set; }
[DefaultValue("")]
[Browsable(true)]
[UrlProperty]
public string ImageUrl
{
get
{
return imgURL;
}
set
{
imgURL = value;
}
}
#endregion
#region Override
protected override void Render(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Id, String.Format("tbl{0}", this.ID));
writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
writer.AddAttribute(HtmlTextWriterAttribute.Class, "imgBtnWrapperStd");
if (!this.Enabled)
writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
writer.AddAttribute(HtmlTextWriterAttribute.Class, "btnContainer");
writer.RenderBeginTag(HtmlTextWriterTag.Div);
if (this.ShowImage)
{
writer.AddAttribute(HtmlTextWriterAttribute.Src, ResolveClientUrl(this.ImageUrl));
writer.AddAttribute(HtmlTextWriterAttribute.Align, "absMiddle");
writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
}
writer.AddAttribute(HtmlTextWriterAttribute.Class, "imgBtnStd");
base.Render(writer);
writer.RenderEndTag();
writer.RenderEndTag();
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
}
#endregion
}
}
单击图像时我还需要触发按钮单击事件