Use directevents on ASP.
When we implement a page request without flushing in ASP. UpdatePanel is usually used, and now Ext.net provides us with another channel: to implement a page request without flushing through directevents.
<Asp:Labelrunat= "Server" > name </asp:Label><asp:TextBox runat= "Server" id= "TxtName"/ ><asp:Button runat= "Server" id= "BtnOK" text= "OK"/>
First, I put a text box and a button on the page, and when we click on the OK button, we want to be able to take the value of the text box in the background.
The next is the time to witness miracles:
<ext:runat= "Server" > <customdirectevents<
Ext:directevent Target
= "Btnok" OnEvent</
Ext:directevent
> </customdirectevents></ext:ResourceManager>
Let's configure a directevent to execute the server-side event method through this directevent, and we'll look at the server-side code:
Btnok_directclick (sender, ext.net. ThisX. Messagebox.alert ("hint"+ name). Show ();}
Through this code, we will take the value of the text box input, and the client pops up a prompt box, and the process is not refreshed. Effect
Use directevents on HTML controls
Asp. NET control can be used, HTML controls can also use Directevents (which is really omnipotent). To see how to use directevents in an HTML button, to demonstrate, I'll add an HTML button to the page:
<typevalueid= "htmlbtn"/>
Then configure the ResourceManager node:
<Ext:resourcemanager runat= "Server "> <customdirectevents> <ext:directevent Target= "htmlbtn" =" Btnok_directclick "> </ext:directevent> </< Span style= "Color:maroon;" >customdirectevents></ext :resourcemanager>
So it's done. When we click on this HTML button, you will see the same effect as above.
Directevents Call WebService
Directevents can also call WebService remotely, in addition to the asynchronous execution of events in the page.
[WebService(Namespace ="http://tempuri.org/")][WebServiceBinding(ConformsTo =WsiProfiles. Basicprofile1_1)][system.componentmodel.ToolboxItem(False)]To allow this Web service to be called from a script using ASP. NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService]public classExtnetservice: System.Web.Services.webservicewebmethod< Span style= "color:black;" >] public directresponse Getservertimewindow () {window ( "Server Time" icon "Mywindow" datetimereturn new directresponse () ; }}
This is the service program that we define and then configure directevents:
<Ext:ResourceManagerRunat= "Server" > <Customdirectevents> <ext:directevent =" htmlbtn "Url = "Extnetservice.asmx/getservertimewindow" Method= "POST" =" Load "> </:directevent> </< Span style= "Color:maroon;" >customdirectevents></ext :resourcemanager>
Then click on the Htmlbtn button, this time will open a small window from the server side:
Note This example, if you go to trace the request process, you will find that this is actually a remote call to the webservice, here and the general URL request is the same, so directevents can invoke the general handler (. ashx)
Directevents calling generic handler (. ashx)
Since a webservice can be called remotely, it is certainly not a problem to call a generic handler remotely.
First look at the code for the generic handler:
public classServertimehandler:IHttpHandler{public voidProcessRequest (httpcontext context) {new Span style= "color: #2b91af;" >window ( "Server Time" icon "Mywindow" datetimenew directresponse (). Return (); } public bool isreusable {get Span style= "color:black;" >{
Then, we modify the directevents configuration, adjust the WebService link just now, the others do not move:
<Ext:ResourceManagerRunat= "Server" > <Customdirectevents> <ext:directevent =" htmlbtn " url = "Servertimehandler.ashx" method= "POST" =" Load "> </:directevent> </< Span style= "Color:maroon;" >customdirectevents></ext :resourcemanager>
After you run the program, you'll see the same effect as calling WebService.
Directevents dynamically generating Ext.net controls
Just now when the demo calls WebService and the generic handler, you've seen how to build the Ext.net control, and then look at the code:
Window("Server time"Icon"Mywindow"DateTime.) Now.tostring ()}. Render (); directresponse();
Note that if you want the window to appear, you must call the Render method.
directevents Updating ASP. NET Control
We know the UpdatePanel update process: First sends an asynchronous request to the server, then the server redraws it, regenerates the control's HTML code, returns it to the client, and finally, the UpdatePanel client JS decides how to replace it to update the page's effect.
Then, you can update the ASP. NET control with Directevents.
Let's go back to the first example by clicking the button to get the value of the text box. We have already completed the process of taking the value in the example, and then we want to assign a value to the text box:
Btnok_directclick (sender, ext.net.
This. txtName.Text = "www.qeefee.com"
;}
Here is the standard method of assignment, if in the ASP. NET UpdatePanel can certainly complete the function we want, but in the ext.net is not OK, do not believe you can try ... Anyway, I tried it.
So how do I update the ASP? I'll tell you the answer:
Btnok_directclick (sender, ext.net. This' www.qeefee.com 'this. txtname.update ();}
See, in addition to the assignment, we also show the call to the Update method.
It is important to note that this update method is a static method in Ext.net, and you must add the Ext.net reference when you use it.
Too complicated to control I have not tried, hope to have a chance to try it later. I hope this article can help everyone ... Don't forget, this is the start of the launch network original first OH
Ext.net Study notes 06:ext.net directevents Supplement