. Net controls interact with Ajax (including datalist, gridview, etc ...)

Source: Internet
Author: User
Because the project must be created using Ajax, datalist remains in the project,
I have never known how to implement datalist as Ajax,
So I searched the internet, but I did not find it again.
Later, I used datalist and page separation in a message board that I had previously done. This idea reminds me to implement Ajax interaction by outputting the datalist control in HTML.

Code
Protected   Override   Void Render (htmltextwriter writer)
{
String SQL =   " Select count (*) from DBO. tb_message where employeeid = "   + Loginid. tostring ();
Int I _recordcount =   Int . Parse (dataaccess. getsingle (SQL, Null ). Tostring ());

If(I _recordcount> 0)
{
Writer. Write (sp. tostring ());
}
This. DB. rendercontrol (writer );
}

CodeThis method can only be used as a reference but cannot be used directly. However, this idea is to rewrite the render method.

Code
VaR S_gridview_currenpage =   ' 0 ' ;
VaR XMLHTTP;
VaR Xmlhttpget;
Function Getxmlhttpobject (){
VaR Xmlhttpnew =   Null ;
Try {
Xmlhttpnew =   New XMLHttpRequest ();
}
Catch (E ){
Try {
Xmlhttpnew =   New Activexobject ( " Msxml2.xmlhttp " );
}
Catch (E ){
Xmlhttpnew =   New Activexobject ( " Microsoft. XMLHTTP " );
}
}
Return Xmlhttpnew;
}

Function Guestbook (){
Xmlhttpget = Getxmlhttpobject ();
If (Xmlhttpget =   Null ){
Alert ( " Sorry, your browser does not support Ajax !; -) " );
Return ;
}
VaR URL =   ' Contactlist. aspx ' ;
URL = URL +   " ? SID = "   + Math. Random ();
URL = URL +   " & Page = "   + S_gridview_currenpage;
Xmlhttpget. onreadystatechange = Bookgetok;
Xmlhttpget. Open ( " Get " , URL, True );
Xmlhttpget. Send ( Null );
}
Function Bookgetok (){
If (Xmlhttpget. readystate =   4 ){
VaR Gustbookdiv = Document. getelementbyid ( " Listdiv " );
Gustbookdiv. innerhtml = Xmlhttpget. responsetext;
}
}

 
I just found that there are also corresponding server controls and JS interactions on the Internet for your reference and mutual learning.

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.