Saturday 25 May 2013

Ajax example program in .NET


First.html:

<html >
<head>
<script language ="javascript" type="text/javascript" >
    function ajaxFunction() {

        var ajaxRequest = new ActiveXObject
("msxml2.xmlhttp");


        ajaxRequest.onreadystatechange =
function () {
    if (ajaxRequest.readyState == 4) {
        f1.t1.value =
ajaxRequest.responseText;

    }
}
        ajaxRequest.open("GET", "first.aspx",
true);
        ajaxRequest.send(null);

    }

</script>

</head> 
<form name="f1">
<input type="button" name="b1" value="clickhere" onclick ="ajaxFunction()" />
<br />
<input type ="text" name="t1" />

</from>
</body>

</html>
-----------------------------------------------------------------------------------------------------------------
First.aspx:
-----------
<%@ Page  Language="C#"  %>
<% Response.Write("ajax"); %>
-----------
second.html
----------
<html >
<head>
<script language ="javascript" type="text/javascript" >
    function ajaxFunction() {

        var ajaxRequest = new ActiveXObject("msxml2.xmlhttp");


        ajaxRequest.onreadystatechange = function () {
            if (ajaxRequest.readyState == 4) {
                f1.t2.value = ajaxRequest.responseText;

            }
        }
        var st = f1.t1.value;
        ajaxRequest.open("GET", "second.aspx?p1="+ st, true);
        ajaxRequest.send(null);

    }

</script>

</head> 
<form name="f1">

<input type ="text" name="t1" onkeyup="ajaxFunction()"/>&nbsp;
<p>
<input type ="text" name="t2" /></p>
</from>
</body>

</form>



</html>
---------
second.aspx:
-----
<%@ Page  Language="C#"  %>
<%int i=Int32 .Parse (Request.QueryString ["p1"]);
    if(i==1)
    {
        Response .Write ("asp.net");
    }
    else if (i == 2)
    {
        Response.Write("Ajax");
    }
    else
    {
        Response.Write("error");
    }
    %>

3 comments:

  1. I really like whaqt you guys are usually up too.
    Such clever work and exposure! Keep up the very good works guys I've
    included you guys to blogroll.

    my blog - how to lose fat fast, http://goviewthis.com/sample-public-front-page.php.txt,

    ReplyDelete
  2. Attractive section of content. I just stumbled upon your weblog and in accession
    capital to assert that I acquire in fact enjoyed account your blog posts.
    Anyway I'll be subscribing to your feeds and even I achievement you access consistently quickly.


    My web page :: lose 1 stone in 7 weeks diet

    ReplyDelete
  3. Rihht now it looks like Movable Type is thhe top blogging platform out there right now.
    (from what I've read) Is that wha you're using on your blog?


    my site blood pressure therapy dog vest for sale

    ReplyDelete