Results 1 to 7 of 7

Thread: Ajax c#

  1. #1

    Default Ajax c#

    This tutorial will show you how to use AJAX with C#.NET to change any part of your web page, without reloading the page (click here for an example). By using the XMLHttpRequest object and split values produced from C#.NET at lightning fast response times, you can change many parts of your website instantly. Simply download the completed working project and modify the code to work on your website to design various AJAX projects with C#.NET like an advanced search, chatrooms, IM’s or whatever. You can go through the 3 documents which include all the instructions you need, or read on…

    Index.html
    The document / front end that the user will see

    1. Include the AJAX code / JavaScript needed to generate the different html parts

    Code:
    <script src="ajax.js" type="text/javascript"></script>
    2. You can call the ”fncResults” function in the <body> tag’s “onload” event to initiate the AJAX result, or you can use various other controls like the textbox’s “onKeyUp”, or a dropdown list’s “onChange” event. Use a value in the brackets to determine what control was last changed to initiate the AJAX request.

    Code:
    <body onLoad="fncResults(0);">
    OR
    <select onChange="fncResults(1);">
    OR
    <input type="text" onKeyUp="fncResults(2);">
    3. Add span tags with IDs around AJAX loading gifs which will notify the user when an AJAX request is being processed.

    Code:
    <span id="spnLoaderSquare"><img src="ajax-loader.gif" /></span>
    <span id="spnLoaderType"><img src="ajax-loader.gif" /></span>
    <span id="spnLoaderPut"><img src="ajax-loader.gif" /></span>
    4. Place span tags and assign an ID to each which will be used to apply dynamic html values in from the ajax.js document using the “innerHTML” property

    Code:
                <tr>
                  <td height="25%">r1</td>
                  <td><span id="spn_R1_C1"></span></td>
                  <td><span id="spn_R1_C2"></span></td>
                  <td><span id="spn_R1_C3"></span></td>
                </tr>
    Ajax.js
    The AJAX / JavaScript code needed to retrieve the values from ajax.aspx, and display them in index.html

    Note: Simply change the values where it is marked: //CHANGE to match your content

    1. This snippet will display or remove the AJAX loading gif when necessary to notify the user that the AJAX info is loading. Change the values ('spnLoaderPut', 'spnLoaderType', 'spnLoaderSquare') to the span tag IDs on your HTML page where you like the loading gif/s to display.

    Code:
    	
    fncVisibility('spnLoaderPut', 'inline');
    fncVisibility('spnLoaderType', 'inline');
    fncVisibility('spnLoaderSquare', 'inline');
    Code:
    	
    fncVisibility('spnLoaderPut', ‘none’);
    fncVisibility('spnLoaderType', ‘none’);
    fncVisibility('spnLoaderSquare', ‘none’);
    2. The following code specifies the path to the C#.NET document where the dynamic values can be retrieved from, and also allow you to pass values using a query string.

    Code:
    	var strUrl = "ajax.aspx";
    	strUrl = strUrl + "?put=" + document.getElementById("ddlPut").options[document.getElementById("ddlPut").selectedIndex].value;
    	strUrl = strUrl + "&typing=" + document.getElementById("txtType").value;
    	strUrl = strUrl + "&square=" + document.getElementById("ddlSquare").options[document.getElementById("ddlSquare").selectedIndex].value;
    	strUrl = strUrl + "&lastchanged=" + strObject;
    3. After retrieving the string produced from the C#.NET document, split the values by assigning the string to an array, then apply each value individually to the different sections of your HTML document. The string is split by the value “[CWAsplit]” in the C#.NET document

    Code:
    		var strCWAsplit = objXmlHttp.responseText.split("[CWAsplit]") 
                    if(strCWAsplit[0]){document.getElementById("spn_R1_C1").innerHTML=strCWAsplit[0];}
    		if(strCWAsplit[1]){document.getElementById("spn_R1_C2").innerHTML=strCWAsplit[1];}
    		if(strCWAsplit[2]){document.getElementById("spn_R1_C3").innerHTML=strCWAsplit[2];}
    		if(strCWAsplit[3]){document.getElementById("spn_R2_C1").innerHTML=strCWAsplit[3];}
    		if(strCWAsplit[4]){document.getElementById("spn_R2_C2").innerHTML=strCWAsplit[4];}
    		if(strCWAsplit[5]){document.getElementById("spn_R2_C3").innerHTML=strCWAsplit[5];}
    		if(strCWAsplit[6]){document.getElementById("spn_R3_C1").innerHTML=strCWAsplit[6];}
    		if(strCWAsplit[7]){document.getElementById("spn_R3_C2").innerHTML=strCWAsplit[7];}
    		if(strCWAsplit[8]){document.getElementById("spn_R3_C3").innerHTML=strCWAsplit[8];}
    		if(strCWAsplit[9]){document.getElementById("spnResult").innerHTML=strCWAsplit[9];}
    Ajax.aspx
    The code behind that will produce the dynamic split values to be retrieved in ajax.js

    Basically what this document does is to print one string value that has split anchor points ("[CWAsplit]") which will be split into any amount of values to apply to various parts of the index.html document. See the attached file for more info
    Attached Files Attached Files
    CWA - CoolWebAwards.com

  2. #2

    Default

    I have never use or study the Ajax before. This is the first time I am looking through the codes above. And it has given me a confidence the I can too learn Ajax. Before that I was bit confused and scared of Ajax, now it’s ok. And I have started searching tutorials in the Internet and found out that AJAX is Asynchronous JavaScript and XML. Ajax deals with data exchange with server, most importantly it updated part of a web page without reloading the whole page. There are lots of wonderful site available for the beginners.

  3. #3

    Default

    I Should suggest you get to grips with the basics first Basic. As this is a Microsoft focused site there are learning resources on asp.net

    Once you have that out of the way you can start to evaluate the various ajax frameworks out there



    Campus Recruitment Company
    Job Placement Agency

  4. #4

    Default

    The AJAX Control Toolkit contains more than 30 free controls that you can use in your ASP.NET applications. In this tutorial, you learn how to download the AJAX Control Toolkit and add the toolkit controls to your Visual Studio/Visual Web Developer Express toolbox.


    Top MBA Colleges in India
    Business School Ranking

  5. #5

    Default

    I think if you are starting to learn web application programming, you should learn XHTML/CSS/JavaScript first.



    Mumbai Schools Ranking
    Mumbai Schools List

  6. #6

    Default

    I am using MVC3 with LinQ and Entity framework and I want to start applying ajax. Where is the best place to start? Does anyone have some good detailed tutorials that could help me get from beginner to advanced?

  7. #7

    Default

    helpful tutorial its been quite sometime since I last picked up the C# book

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •