asp.net2.0 a custom control---Pop-up OK and cancel dialog box

Source: Internet
Author: User



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>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.