In a practical application in the confirm confirmation box, I used the icallbackeventhandler interface to rewrite the previous scheme.
The form post method is used for rewriting.
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead runat = "server"> <br/> <title> </title> <br/> <SCRIPT type = "text/JavaScript"> <br/> function customsubmit () {<br/> var form = document. getelementbyid ('<% = form1.clientid %>'); <br/> document. getelementbyid ('hid '). value = Co Nfirm ('Are you sure you want to execute? '); <Br/> form. submit (); <br/>}</P> <p> </SCRIPT> <br/> </pead> <br/> <body> <br/> <Form ID =" form1 "runat =" server "> <br/> <input type =" hidden "id =" hid "name =" hname "/> <br/> <asp: button id = "btncallback" runat = "server" text = "send back and pop up confirm" onclick = "btncallback_click"/> <br/> <ASP: literal id = "login" runat = "server"> </ASP: literal> <br/> </form> <br/> </body> <br/> </ptml> <br/>
Private dictionary <bool, Action> DIC; </P> <p> protected void page_load (Object sender, eventargs e) <br/>{< br/> string value = request. form ["hname"]? ""; </P> <p> bool result; </P> <p> If (bool. tryparse (value, out result) <br/>{< br/> DIC = new dictionary <bool, Action> (); </P> <p> dic. add (true, confirm); <br/> dic. add (false, cancel); </P> <p> DIC [Result] (); <br/>}< br/> protected void btncallback_click (Object sender, eventargs E) <br/>{< br/> // run a piece of code <br/> quit. TEXT = datetime. now. tostring ("yyyy-mm-dd"); </P> <p> // pop-up confirm </P> <p> clientscript. registerstartupscript (GetType (), "Confirm", "customsubmit ();", true ); <br/>}</P> <p> // code executed upon confirmation <br/> private void confirm () <br/>{< br/> confirm. TEXT = "OK"; <br/>}</P> <p> // code executed during cancellation <br/> private void cancel () <br/> {<br/> enabled. TEXT = "cancel"; <br/>}