------- Windows Phone 7 Mobile Phone development,. Net training, and we look forward to communicating with you! -------
Using XML in Ajax, I learned how to use this in this lesson to implement a text that displays the login name of a logon user on the template page, when you move the mouse over the content page to display the I login name, other information of the user will be displayed.
First, you need to create a general processing program,
The Code is as follows:
<% @ Webhandler Language = "C #" class = "getuser" %> using system; using system. web; using bookshopbll; using bookshopmodels; using system. XML. serialization; using system. XML; public class getuser: ihttphandler {public void processrequest (httpcontext context) {context. response. contenttype = "text/XML"; // verify that the passed value is not null if (context. request. querystring ["loginid"]! = NULL) {// obtain the loginid (login name) string loginid = context. request. querystring ["loginid"]. tostring (); // use the user class to receive user information searched by login name // users ouser = bookshopbll. usermanage. getusersbyloginid ("bobo"); // test User Users ouser = bookshopbll. usermanage. getusersbyloginid (loginid); If (ouser! = NULL) {// is an abstract class xmlwriter writer = NULL; try {// create an xmlserializer object xmlserializer serializer = new xmlserializer (ouser. getType (); // assign the xmlwriter object to the xmltextwriter object writer = new xmltextwriter (context. response. outputstream, system. text. encoding. utf8); // call the serialization method serializer. serialize (writer, ouser);} finally {If (writer! = NULL) {writer. Close () ;}}} public bool isreusable {get {return false ;}}}
Then write the JS Code on the template page to accept:
<SCRIPT type = "text/JavaScript" Language = "JavaScript"> function createxmlhttprequest () {If (window. activexobject) {// for IE browser return New activexobject ("Microsoft. XMLHTTP ");} else if (window. XMLHttpRequest) {// non-IE browser return New XMLHttpRequest () ;}} function getuser (loginid) {If (loginid! = NULL) {// get the server URL var url = "ajaxhandler/getuser. ashx? Loginid = "+ loginid; // create XMLHttpRequest var xhr = createxmlhttprequest (); // set the callback function xhr. onreadystatechange = function () {If (xhr. readystate = 4 & xhr. status = 200) {var dom = xhr. responsexml; // get the data sent by the server in XML format // read the XML data document. getelementbyid ("name "). innerhtml = Dom. getelementsbytagname ("name") [0]. text; document. getelementbyid ("Address "). innerhtml = Dom. getelementsbytagname ("Address") [0]. text; document. getelementbyid ("phone "). innerhtml = Dom. getelementsbytagname ("phone") [0]. text; document. getelementbyid ("mail "). innerhtml = Dom. getelementsbytagname ("mail") [0]. text; // set to Display User details document. getelementbyid ("userinfo "). style. display = "inline" ;}}// initialize XMLHttpRequest ------- true indicates that xhr can be asynchronous. open ("get", URL, true); // send the request xhr. send (null) ;}// the setting does not show the user details function closeuser () {document. getelementbyid ("userinfo "). style. display = "NONE" ;}</SCRIPT>
Set mouse events:
<Asp: linkbutton id = "lbtn_user" runat = "server" onmouseover = 'getuser (this. innerhtml) 'onmouseout = 'closeuser ()'> User </ASP: linkbutton>
Display:
<Div class = "userinfo" id = "userinfo" style = "display: none"> <p> <label> Name: </label> <label id = "name"> </label> </P> <p> <label> address: </label> <label id = "Address"> </label> </P> <p> <label> Tel: </label> <label id = "phone"> </label> </P> <p> <label> mail: </label> <label id = "mail"> </label> </P> </div>
------- Windows Phone 7 Mobile Phone development,. Net training, and we look forward to communicating with you! -------