/ * * Before watching this control code, you must be familiar with the following: * 0. ViewState mechanism and function. * 1. Event mechanism. * 2. Return mechanism: Keep client changes in non-form controls, ms-help: //ms.vscc.2003/ms.msdnqtr.2003feb.2052/cpguide-sidechangesinnon-form-form-sidechangesinnon-form 3. The role and implementation of iPostBackDataHandler. * This control is an ASP.NET server control. The Confirm is popped, confirming the submission function. * When the button is clicked, the Confirm is popped up, prompted to confirm the operation, such as: Used to confirm the deletion. * After clicking "Yes", submit the trigger Cliektrue event, such as: You can write the deleted code inside the event. * * Addition: Call code * * * Addition: Do not write EventDataArgs and EventDataHandler in the namespace because many classes will inherit these two classes, can be used directly without reference numerals. * * / Using system; using system.collections.specialized; using system.drawing; using system.web; using system.Web.ui;
Namespace CenxaoiWebControls {Public Class WebConfirm: Control, InamingContainer, iPostBackDataHandler {/// /// Client Click on "OK" to trigger the server event. After the CliekTrue is executed, E. SecureMessageData is reset to null. /// summary> / 提 信息 信息 {g {Object obj = viewstate ["message"]; Return ("Message"]; RETURN Obj == null)? String.empty: (string) Obj;}
Set {ViewState ["Message"] = value;}}
/// /// Call the data information belled by the showconfirmbox function, which can be received in Cliektrue. After the Cliektrue is executed, OtherMessageData is reset to NULL. /// summary> Protected Object OtherMessageData {Get {Return ViewState ["OtherMessage"];} set {viewstate ["}"] = value;}}
/// /// Return data hidden domain ClientID /// summary> protected string helperid {get {return "__" clientid "_state";}} /// // / Register the control to register the control, in initialization, /////mmary> protected override void oninit (Eventargs e) {base.oninit (e); if (page! = Null) Page.registerRequirespostback (this) } Protected override void onprender (Eventargs E) {base.onprender (e); if (page! = Null) {page.registerhiddenfield (helperid, ");}}
/// /// IPostBackDataHandler implement interfaces /// summary> bool IPostBackDataHandler.LoadPostData (string postDataKey, NameValueCollection postCollection) {string value = postCollection [HelperID]; / * * Because the value taken from the dictionary, unknown Whether to get, all Value keyword storage variables can be judged with NULL. * Hidden domain has a valid value * / if (null! = Value && value.tolower (). Indexof ("true")> - 1) Return true; return false; // does not trigger RaisePostDataChangeDevent event} /// / // IPostBackDataHandler implement interfaces /// summary> void IPostBackDataHandler.RaisePostDataChangedEvent () {if (CliekTrue = null!) {CliekTrue (this, new EventDataArgs (this.OtherMessageData)); this.OtherMessageData = null; // event execution After clearance this.OtherMessageData reference. }} /// /// The client issued a confirmation box. /// summary> /// in ClickTrue event, the data may be used to param> public void ShowConfirmBox (object otherMessageData) {ShowConfirmBox (this.Message, otherMessageData);} /// /// client issued a confirmation box. /// summary> /// In the ClickTrue event, you can use the data param> /// confirm prompt information param> public void ShowConfirmBox (string message, object otherMessageData) {this.OtherMessageData = otherMessageData;. Page.RegisterStartupScript ( "__ ShowConfirmBox", "