Ajax implemented in ASP.net (3)

Source: Internet
Author: User
Tags functions httpcontext net return string wrapper
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 .




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.