Get the confirm Click Event [custom control]

Source: Internet
Author: User

 

Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. componentmodel;

/* Configure /*------------------------------------------------------------------------------------
* File name: MessageBox. CS

* File Function Description: Excel Import and Export
*
* Create an ID: Liu Jia Jun 20081128
*
* Modify the ID:
* Description:
*
*----------------------------------------------------------------------------------*/
Namespace i799net
{
 
[Serializable, designtimevisible, toolboxdata ("<{0}: MessageBox runat = \" Server \ "> </{0}: MessageBox>")]
Public class MessageBox: webcontrol
{
// Fields
Private const string cancel = "cancel"; // "cancel ";
Private string content;
Private string m_session = "msgsession ";
Private const string notpressed = "notpressed ";
Private const string OK = "OK"; // "OK ";

// Events
Public event message getmessageboxresponse;

// Methods
Public void alert (string message)
{
String STR = message. Replace ("\ n", @ "\ n ");
STR = message. Replace ("\"","'");
Stringbuilder builder = new stringbuilder (50 );
Builder. append ("<script language = 'javascript '> ");
Builder. append ("alert (\" "+ STR + "\");");
Builder. append ("</SCRIPT> ");
This. content = builder. tostring ();
}

Public void confirm (string message)
{
This. Confirm (message, null );
}

Public void confirm (string message, object data)
{
String STR = message. Replace ("\ n", @ "\ n ");
STR = message. Replace ("\"","'");
Stringbuilder builder = new stringbuilder (100 );
Builder. appendformat ("<input type = 'den den 'value =' {0} 'name = '" + this. hiddenfieldname + "'/>", "notpressed ");
Builder. append ("<script language = 'javascript 'Type = 'text/JavaScript '> ");
Builder. append ("If (confirm (\" "+ STR + "\"))");
Builder. append ("{");
Builder. append ("document. forms [0]. "+ this. hiddenfieldname + ". value = 'OK'; document. forms [0]. submit ();}");
Builder. append ("else {");
Builder. append ("document. forms [0]. "+ this. hiddenfieldname + ". value = 'cancel'; document. forms [0]. submit ();}");
Builder. append ("</SCRIPT> ");
This. content = builder. tostring ();
If (Data! = NULL)
{
This. Page. session [This. m_session + this. clientid] = data;
}
}

Protected override void onload (eventargs E)
{
Object Data = NULL;
String STR = This. Page. Request. Form [This. hiddenfieldname];
If (STR! = NULL)
{
If (! (STR = "OK "))
{
If (STR = "cancel ")
{
This. Page. Request. Form [This. hiddenfieldname]. Replace ("cancel", "notpressed ");
If (this. Page. session [This. m_session + this. clientid]! = NULL)
{
Data = This. Page. session [This. m_session + this. clientid];
This. Page. session. Remove (this. m_session + this. clientid );
}
This. onmessageboxshow (New messageboxeventhandler (messageboxeventhandler. Button. Cancel, data ));
}
Else if (STR = "notpressed ")
{
}
}
Else
{
This. Page. Request. Form [This. hiddenfieldname]. Replace ("OK", "notpressed ");
If (this. Page. session [This. m_session + this. clientid]! = NULL)
{
Data = This. Page. session [This. m_session + this. clientid];
This. Page. session. Remove (this. m_session + this. clientid );
}
This. onmessageboxshow (New messageboxeventhandler (messageboxeventhandler. Button. OK, data ));
}
}
Base. onload (E );
}

Protected virtual void onmessageboxshow (messageboxeventhandler E)
{
If (this. getmessageboxresponse! = NULL)
{
This. getmessageboxresponse (this, e );
}
}

Protected override void render (htmltextwriter output)
{
If (! Base. designMode)
{
Output. Write (this. content );
}
Else
{
Label Label = new label ();
Label. Font. Bold = This. Font. Bold;
Label. Font. italic = This. Font. italic;
Label. Font. Names = This. Font. names;
Label. Font. overline = This. Font. overline;
Label. Font. size = This. Font. size;
Label. Font. Strikeout = This. Font. Strikeout;
Label. Font. Underline = This. Font. Underline;
Label. forecolor = This. forecolor;
Label. backcolor = This. backcolor;
Label. bordercolor = This. bordercolor;
Label. borderstyle = This. borderstyle;
Label. borderwidth = This. borderwidth;
Label. Text = This. ID;
Label. rendercontrol (output );
}
}

// Properties
Private string hiddenfieldname
{
Get
{
Return ("hidf" + this. ID );
}
}

// Nested types
Public Delegate void message (Object sender, MessageBox. messageboxeventhandler E );

Public class messageboxeventhandler: eventargs
{
// Fields
Public readonly button buttonpressed;
Public readonly object data;

// Methods
Public messageboxeventhandler (Button buttonpressed): This (buttonpressed, null)
{
}

Public messageboxeventhandler (Button buttonpressed, object data)
{
This. buttonpressed = buttonpressed;
This. Data = data;
}

// Nested types
Public Enum button
{
OK,
Cancel,
Notpressed
}
}
}

 
 
 

}

 
 
 

 

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.