Recent Articles

 
1: Read And Write XML with Dataset
Category: VB.NET
Added: 2/11/2009

 
2: Split Ajax Tab Control into Rows
Category: AJAX
Added: 2/2/2009

 
3: Path Less Css in Master Page in Asp.Net
Category: ASP.Net
Added: 1/27/2009

 
4: Prevent user going back to restricted area
Category: ASP.Net
Added: 1/25/2009

 
5: Sql Server MSC Error
Category: Databases
Added: 1/10/2009

 
6: Web Browser Control Javascript Close Button Error
Category: VB.NET
Added: 1/3/2009

 
7: ChartFX Volume in Candlestick without Extensions
Category: VB.NET
Added: 1/3/2009

 
8: Hard disk serial number Library
Category: VB.NET
Added: 1/3/2009

 
9: Roles And Membership
Category: ASP.Net
Added: 6/2/2008

 
10: ListView and DataPager in ASP.NET 3.5
Category: ASP.Net
Added: 5/15/2008

Ajax With Javascript

by Imran 10/March/2008
Create a simple page like

Default.aspx

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>

    <script language="Javascript">
function xmlhttpPost(strURL) {
   // alert(strURL)
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {alert('hi');
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
    var form     = document.forms['f1'];
    var word = form.word.value;
    qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(str){
    alert(str)
    document.getElementById("result").innerHTML = str;
}
    </script>

</head>
<body>
   <form name="f1">
  <p>word: <input name="word" type="text"> 
  <input value="Go" type="button"
        onclick='JavaScript:xmlhttpPost("http://localhost:2835/website1/WebService.asmx/HelloWorld")'></p>
  <div id="result"></div>
    </form>
</body>
</html>

Then Create a webservice

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
     Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function

End Class




Powered by DotNetClassic.com