Sessionstate
The server functions may need to access session information. Therefore, you only need to tell ajax to enable this function by passing a parameter to the Ajax. ajaxmethod attribute.
While examining the package's session capabilities, let's take a look at several other features. In this example, we have a document management system that locks documents when users edit them. Other users can request a notification when the document is available. Without Ajax, we can only wait for the user to return again to check whether the requested document is available. Obviously not ideal. It is very easy to use Ajax that supports session status.
First, write the server-side function. The objective is to traverse the entid that you want to edit (stored in the session) and return all released documents.
[Ajax. ajaxmethod (httpsessionstaterequirement. Read)]
Public arraylist documentreleased (){
If (httpcontext. Current. session ["documentswaiting"] = NULL ){
Return NULL;
}
Arraylist readydocuments = new arraylist ();
Int [] documents = (INT []) httpcontext. Current. session ["documentswaiting"];
For (INT I = 0; I <documents. length; ++ I ){
Document document = Document. getdocumentbyid (documents [I]);
If (document! = NULL & document. Status = documentstatus. Ready ){
Readydocuments. Add (document );
}
}
Return readydocuments;
}
}
Note that the value httpsessionstaterequirement. Read is specified (write and readwrite can also be used ).
Now write the Javascript that uses this method:
<Script language = "JavaScript">
Function documentsready_callback (response ){
If (response. Error! = NULL ){
Alert (response. Error );
Return;
}
If (response. value! = NULL & response. value. length> 0 ){
VaR DIV = Document. getelementbyid ("status ");
Div. innerhtml = "The following statements are ready! <Br/> ";
For (VAR I = 0; I <response. value. length; ++ I ){
Div. innerhtml + = "<a href = \" Edit. aspx? Entid = "+ response. value [I]. entid +" \ ">" + response. value [I]. Name + "</a> <br/> ";
}
}
SetTimeout ('page. documentreleased (documentsready_callback) ', 10000 );
}
</SCRIPT>
<Body onload = "setTimeout ('document. documentreleased (documentsready_callback) ', 10000);">
Our server-side functions are called every 10 seconds during page loading. The callback function checks the response to see if there is any returned value. If yes, the new document that this user can use is displayed in the DIV tag.
Conclusion
Ajax technology has given birth to a robust and rich web interface that was originally available only for desktop development. The Ajax. Net package allows you to easily use this new powerful technology. Please note that the Ajax. Net Package and documentation are still under development. Http://www.shpan.com/Detail.asp? Id = 400