If you want to add a dialog box to a button, you usually use the following methods:
BUTTON1.ATTRIBUTES.ADD ("OnClick", "Return Confirm" (') is submitted. ');");
BUTTON1.ATTRIBUTES.ADD ("onclick", "if" (confirm) is submitted. ')) {return true;} Else{return false;} ");
Now let's make her a control.
1, establish the project Zgdxbutton and three class Normalbutton.cs,imgbutton.cs, LinkButton.cs
2, NormalButton.cs code as follows
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Text;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Drawing;
Namespace Zgdxbutton
{
[Defaultproperty ("Text")]
[ToolBoxData ("<{0}:normalbutton runat=server></{0}:normalbutton>")]
public class NormalButton:System.Web.UI.WebControls.Button
{
private string _confirmmessage = "";
Public Normalbutton ()
: Base ()
{
Base. Text = "button";
}
[Bindable (True),
Category ("appearance"),
DefaultValue (""),
Description ("Input pop-up hint content, Yanbian Adult College (China. Yanji)")]
public string Confirmmessage
{
Get
{
return _confirmmessage;
}
Set
{
_confirmmessage = value;
}
}
EditorAttribute: Specifies the editor version used to change the property
<summary>
Specify help information for a control
</summary>
private string _help = "Help";
[CategoryAttribute ("Custom editor"),
DefaultValueAttribute ("1.0"),
DescriptionAttribute ("Help information, Yanbian Adult College (China. Yanji)"),
ReadOnlyAttribute (True),
EditorAttribute (typeof (Appverconverter), typeof (System.Drawing.Design.UITypeEditor))]
public string Help
{
get {return this._help;}
set {this._help = value;}
}
<summary>
Custom UI Property Editor (pop-up message)
</summary>
public class AppVerConverter:System.Drawing.Design.UITypeEditor
{
<summary>
Override this method to return the type of the editor.
</summary>
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle ( System.ComponentModel.ITypeDescriptorContext context)
{
return System.Drawing.Design.UITypeEditorEditStyle.Modal;
}
<summary>
Override this method to display version information, Button control, version V1.0
</summary>
public override Object EditValue (System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider Provider, object value)
{
String help = "pop-up hint button control assistance information";
Help + = "main attributes:";
Help + = "Confirmmessage property: Fill out the pop-up prompts, and do not write the same as the normal control. ";
Help + = "Development Author: Yanbian Adult College." Xu Teacher Online support: xuhongkaicn@yahoo.com.cn ";
Help + = "Version update: version1.0:2007 year";
System.Windows.Forms.MessageBox.Show (Help, "helping information");
return value;
}
}
<summary>
Renders this control to the specified output parameter.
</summary>
<param name= "Output" > HTML writer to write </param>
protected override void Render (HtmlTextWriter output)
{
if (this._confirmmessage!= "")
{
Base. Attributes.Add ("OnClick", "return Confirm ('" + This._confirmmessage + ");");
}
Base. Render (output);
}
}
}
3, ImgButton.cs code is as follows:
Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Text;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Drawing;
Namespace Zgdxbutton
{
[Defaultproperty ("Text")]
[ToolBoxData ("<{0}:imgbutton runat=server></{0}:imgbutton>")]
public class ImgButton:System.Web.UI.WebControls.ImageButton
{
private string _confirmmessage = "";
[Bindable (True),
Category ("appearance"),
DefaultValue (""),
Description ("Input pop-up hint content, Yanbian Adult College (China. Yanji)")]
public string Confirmmessage
{
Get
{
return _confirmmessage;
}
Set
{
_confirmmessage = value;
}
}
EditorAttribute: Specifies the editor version used to change the property
<summary>
Specify help information for a control
</summary>
private string _help = "Help";
[CategoryAttribute ("Custom editor"),
DefaultValueAttribute ("1.0"),
DescriptionAttribute ("Help information, Yanbian Adult College (China. Yanji)"),
ReadOnlyAttribute (True),
EditorAttribute (typeof (Appverconverter), typeof (System.Drawing.Design.UITypeEditor))]
public string Help
{
get {return this._help;}
set {this._help = value;}
}
<summary>
Custom UI Property Editor (pop-up message)
</summary>
public class AppVerConverter:System.Drawing.Design.UITypeEditor
{
<summary>
Override this method to return the type of the editor.
</summary>
public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle ( System.ComponentModel.ITypeDescriptorContext context)
{
return System.Drawing.Design.UITypeEditorEditStyle.Modal;
}
<summary>