Ajax|asp.net
return Unicode characters
Ajax. NET wrapper to return Unicode characters from the server to the client machine . to do this, the data must be HTML encoded on the server before it is returned . For example:
[Ajax.ajaxmethod]
public string Test1 (string name, string email, string comment) {
String html = "";
html = "Hello" + name + "
";
HTML + + "Thank for your comment ";
HTML + System.Web.HttpUtility.HtmlEncode (comment);
html = ".";
return HTML;
}
sessionstate
Session information is likely to be accessed in server -side functions . to do this, you only need to tell Ajax to enable this functionality by passing a parameter to the Ajax.ajaxmethod property .
While examining the ability of the wrapper session, let's look at a few other features . In this example we have a document management system that locks the document when the user edits it . other users can request notification when the document is available . without Ajax, we can only wait for the user to return again to check that the requested document is available . is clearly not ideal . using AJAX, which supports session state, is very simple .
The first is to write a server -side function that iterates through the DocumentID (saved in session) that the user wants to edit and returns all the freed 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 we have specified the Httpsessionstaterequirement.read value (you can also use write and ReadWrite).
Now write JavaScript that uses this method:
Our server -side functions are called once on the page load and then called once every 10 seconds . The callback function checks the response to see if there is a return value, and in some cases it displays a new document that the user can use in the div tag .
Conclusion
Ajax technology has spawned a robust and rich web interface ajax that only desktop development has. NET wrapper makes it easy for you to take advantage of this new and powerful technology . please note that Ajax. NET wrappers and documents are still under development .