在线急等控件开发问题
Rysen 2006-04-28 11:23:02 刚开始学习控件开发,有一个弱弱的问题求救~
怎么在设置的属性为true时,才调用事件,否则不调用
源码如下
using System;
using System.ComponentModel;
using System.Text;
using System.Web.UI.WebControls;
namespace Service
{
public class DelConfirmButton : Button
{
private bool IsConfirm;
[Browsable(true), DefaultValue(true), Description("是否允许弹出删除提示")]
public bool DelConfirm
{
get { return IsConfirm; }
set { IsConfirm = value; }
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (!Page.IsPostBack)
{
StringBuilder scriptString = new StringBuilder();
scriptString.Append("<script language=JavaScript> ");
scriptString.Append("function DelConfirm() {");
scriptString.Append("return confirm('确认删除吗?');}");
scriptString.Append("</script>");
String js = scriptString.ToString();
if (!this.Page.IsClientScriptBlockRegistered("DelConfirm"))
{
this.Page.RegisterClientScriptBlock("DelConfirm", js);
this.Attributes.Add("onclick", "return DelConfirm()");
}
}
}
}
}