Tuesday, June 30, 2009

Protype objects using Javascript

I have come across some aritcle for javascript. just thought of sharing this to everyone.so that am writing this in my blog.

let me explain my faurouite Prototype objects in the javascript. If you want to write libraries and learn advance in javascript. please try to learn prototype objects. It will be very use full.


Protytype objects.

Prototype is the keyword, Using this, we can add the custom properties and methods. Let me go through in detail.

Let me explain about custom properties in prototype objects.

function circle()
{
//
}

circle.prototype.pi="3.14";

This PI property is common for all the instances of the methods.


Custom Methods:

function ReverseBack()
{
for(i=this.length-1;i<=0;i--)
{
document.write(this.charAt(i));
}
}

String.Protype.writeBack=ReverseBack();

var message1="Bala";
var message2="alaB";

message1.writeBack();
message2.writeBack();

Output:
alaB;
Bala;





Disabling the Drag for Source Object

Take this scenario, I have the table, in that having list of names, As per business logic some names should not allow the drag and drop functionality.

For that have to use set_cancel method. According to the condition it will not allow the drag and drop.

Example

ddb=new $Ig.DragDropBehaviour();
ddb.get_events().addDragStartHandler(DragStartHandler);

function DragStartHandler(sender, args)
{
args.set_cancel(true);
return;
}




Monday, June 29, 2009

Javascript Best Practices 6

Reduce Globals

Try to avoid the global variable in the javascirpt code. Instead of that use the method objects.


var name = 'Jeffrey';
var lastName = 'Way';
function doSomething() {...}


Better way of writing the code.

var DudeNameSpace =
{
name :'Bala',
lastname:'Subramaniyam',
doSumething : function()
{
//do something
}
}

}




Drag & Drop Events-Infragistics

1) addDragMoveHandler--- it will work, While moving the jobs from origin to destinaton origin.

2) addDragStartHandler-- When starting of drag will work., In this we can cancel the event using args.set_cancel(true);

3) addDragEndHandler--- it will work, After drop handler event fired,

4) addDragLeaveHandler--- it will work,after move out from the source block,

5) addDragCancelHandler--- it will work, After dragging not dropping to destination.

6) _removeHandler --It will remove only specified event handler.

7) clearHandler--It will clear all the event handler.

Validation Drag & Drop Infragisitics.

We are facing one problem in the Current project, The issue is dragging the jobs from source and droping to destination.

In the destination am doing validation, if the validation has fails. We should not drop the jobs and it should go back to the destination automatically. Still i didnt found the solution. Even had a discussion with the infragistics. hopefully will get the solution soon.

For the above i have found the alternate solution.

I am using the copy and paste method for dragging the jobs.

If the validation fails in the destionation. i will not drop the destionation. so no need to go back the source. Already will have to data in the source. Because we are using the copy and paste method.

Example


Sys.Application.add_load(appLoaded);
function appLoaded(){
var ddb = new $IG.DragDropBehavior();
var list = $get("imageList");
var count = list.childNodes.length;
var child;
for (var i = 0; i <>
child = list.childNodes[i];
if (child.getAttribute) {
ddb.addSourceElement(child);
}
}
ddb.addTargetElement($get("cartAreaDiv"), true);
ddb.get_events().addDropHandler(dropHandler);
}
function dropHandler(sender, args){
var srcItem = args.get_manager().get_source().element;
var target = $get("cartAreaDiv");
//debugger;
if (srcItem.id == "CD"){
alert("You can't add a CD!"); Validatiion got failed.
}
else{
target.appendChild(srcItem);
}
}



Drag & Drop Basics-Infragistics

Let me discuss some of the basic things about the Infragistics frame work. We have two type of drag and drop in the Infragistics.

1)Copy and paste. (Source will not delete, it will append to the destination)

2)Cut and paste. (Source will delete, it will not append to the destination)

If you want to enable the 1st one have to include the below code.

var ddb = new $IG.DragDropBehavior();

And include below code to enable the 2nd one.

var ddb = new $IG.DragDropBehavior();
var date = $get("ctl00_ContentPlaceHolder1_lblDate");
var wcgId = $get("ctl00_ContentPlaceHolder1_wcg_id");




Wednesday, June 24, 2009

Javascript Best Practices 5

Eval = Bad

Eval is the function, it will execute the string in to script code.

It will run through javascript compiler. So that it will reduce the performance of the code
Substantially.

for better code dont use Eval..






Javascript Best Practices 4

Use Always === operator, instead of ==

The issue of this operator (==) is, if the variable are different types it does not compare. It's end up with javascript error.

But in this operator( === ) variable will be converted in to objects. and it will compare.

1)!=
2) ==

Bettor Coding use below opertor instead of above.

1)!==
2)===







Tuesday, June 23, 2009

Javascript Best Practices 3

One interesting thing have faced today in the javascript. I was tried nearly two hour to enabling the focus for html tags (like table, tr, th). It does not work out.

After concluded we can give focus only for controls like textbox, button. Anchor tag..

So that I have used Anchor tag in my task.

Note:Hidden field can't give focus.




Custom ProgressBar using Javascript

Step 1:
Create below div tags in the aspx page.

<div id="modalOut" class="modalProgressOuter">
<div id="modalIn" class="modalProgressIn">
<img src="../../Themes/Theme2/ig_progressIndicator.gif" />
</div>
</div>

Step 2:

Create stylesheet with below classes.

div.modalProgressOuter
{
background-color:White;
filter:alpha(opacity=40);
opacity:0.4;
position:absolute;
display:none;
}
div.modalProgressIn
{
vertical-align:middle;
}

Step 3:

Call the below javascript through control, i mean when you click on submit button..

function showProgress() {
var objModalProgress = document.getElementById("modalOut");
var objModalIn = document.getElementById("modalIn");
if (objModalProgress != null) {
objModalIn.style.marginLeft = parseInt(document.body.offsetWidth) / 2;
objModalIn.style.marginTop = parseInt(document.body.offsetHeight) / 2;
objModalProgress.style.height = document.body.offsetHeight;
objModalProgress.style.width = document.body.offsetWidth;
objModalProgress.style.display = "block";
objModalProgress.style.left = 10;
objModalProgress.style.top = 25;
}
}





Javascript Best Practices 2

Always, Always Use Semicolons.

If you not use ;(semicolon) in the code, it's very difficult to find the error.

So please try to use everystatement with semi colon.

var someItem = 'some string'
function doSomething() {
return 'something'
}

Better

var someItem = 'some string';
function doSomething() {
return 'something';
}

Javascript Best Practices 1

Remove "Language" in the Script tag
we have used years ago, Because we unable to find that language.

Now its deprecated, so leave it out.
<script type="text/javascript" language='javascript' >
...
</script >

Itextsharp

Itextsharp

I have come across this from one of my friend, I just thought of sharing with everyone. i am writing in my blog.

This is opensource library, Which will create the PDF on the fly. Basically its taken from java library. now purely written in the C#.NET

Everyone can use this library with .net framework 1.1 and 2.O


You can download the dll in the given URL

http://sourceforge.net/projects/itextsharp/

Monday, June 22, 2009

C# 4.0 -Optional Parameters

I was really excited, when i have seen upcoming feature in c# 4.0, After come across some article, This feature will be very useful.


Optional Parameters

Let’s say I have a class Employee and I provide few overloads of the constructor to enable making certain parameters as optional as follows:

Older Method

public class Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Qualification { get; set; }
public string MiddleName { get; set; }

public Employee(string firstName, string lastName)
{
FirstName= firstName;
LastName= lastName;
Qualification= "N/A";
MiddleName= string.Empty;
}
public Employee(string firstName, string lastName, string qualification)
{
FirstName= firstName;
LastName= lastName;
Qualification= qualification;
MiddleName= string.Empty;

}
public Employee(string firstName, string lastName, string qualification,
string middleName)
{
FirstName= firstName;
LastName= lastName;
Qualification= qualification;
MiddleName= middleName
}
}

Newer Method

public Employee(string firstName, string lastName,
string qualification = "N/A", string middleName = "")
{
FirstName= firstName;
LastName= lastName;
Qualification= qualification;
MiddleName = middleName;
}

Drag & Drop In Infragistics New Framework

Infragistics(2009.1), In the new version drag & drop features implemented. We can implement this feature in the html element.

Note:This is very good support for DIV element in the HTML. Dont use other thin div. when you add more functionality in the page, it may give problem when you use other than DIV.

Make sure Div elment in the outermost..

Example:

<div id="tech1"><table><tbody><tr><td></td></tr></tbody></table>
</div>


Step 1:

Download original version from Infragistics 2008 or 2009

Step 2:

Download below three files from Infragistics installed folder.

1)igDragDrop.js
2)5_igObjects.js
3)igAnimation.js

Maintain same order, when you add the Above javascript in the page.

Step 3:

Add the below script in the page, which you are going to implement the drag & drop feature.This is the script will allow the drag and drop feature.

<script type="text/javascript">
if (typeof (Sys) !== 'undefined')
{
Sys.Application.notifyScriptLoaded();
Sys.Application.add_load(appLoaded);
}
</script>

Step 4:

In the below script have two method which will enable the drag & drop for html elements.Also am adding the script in the addsource element and adddrag element.

1)addSourceElement
2)addTargetElement

It will deside the from and destination of the elements.

function appLoaded() {
ddb = new $IG.DragDropBehavior();
ddb.set_defaultDropAction($IG.DragDropAction.Insert);
ddb.set_dragDropMode($IG.DragDropEffects.Move);
var list = $get("DragUnassign");
var count = list.childNodes.length;
for (var i = 0; i <>
var child = list.childNodes[i];
if (child.getAttribute)
ddb.addSourceElement(child);
}
for (var k in techIds) {
ddb.addTargetElement($get(techIds[k]), true); //Techids nothing but a div //element of the id
var jobs = $get(techIds[k]);
if (jobs != null) {
if (jobs.childNodes != null) {
var jobCount = jobs.childNodes.length;
for (var x = 0; x <>
var job = jobs.childNodes[x];
if (job.getAttribute)
ddb.addSourceElement(job);
}
}
}
}
ddb.addTargetElement($get("DragUnassign"), true);
ddb.get_events().addDropHandler(dropHandler);
var autoComplete = $find('Auto');
}

Step 5:

In this method "$IG.DragDropBehavior()" we have method called drop Handler.

This is method it will enable the events.


Note:In the present version, It cannot write a server side method for the drag & drop feature.

Step 6:


This is the method will call the webservice.

function dropHandler(sender, args)
{
var manager = args.get_manager();
if (args.get_manager()._dragging == true) {
var progressEnable = false;
var target = manager.get_targetElement().id.replace("tech", "");
techId = target;

var obtblid = techId.replace("tech", "parent");
var sourceElement = manager.get_source().element.id;
var sourceObject = manager.get_source().element.offsetParent.id;
////////////////////This is for Dragging & droping Jobs from Unassigned to Technician////////////
if ((sourceObject == "DragUnassign") && (manager.get_targetElement().id.indexOf("tech") != -1)) {
progressEnable = true;
LTDWebApp.WebClient.WebPages.Dispatcher.TechDetails.AssignJob(target, sourceElement,drcCommitdate, "ADD", onSuccessDrag, onFailureDrag);
}
//////////////////// End for Dragging Jobs from Unassigned to Technician////////////////////////
////////////////////This is for Dragging & droping Jobs from Technician to Technician////////////
else if ((sourceObject.indexOf("tech") != -1) && (manager.get_targetElement().id.indexOf("tech") != -1)) {
progressEnable = true;
LTDWebApp.WebClient.WebPages.Dispatcher.TechDetails.AssignJob(target, sourceElement,drcCommitdate, "UPDATE", onSuccessDrag, onFailureDrag);
}
////////////////////End for Dragging & droping Jobs from Technician to Technician////////////
else
{
////////////////////This is for Dragging & droping Jobs from Technician to Unassigned ////////////
progressEnable = true;
LTDWebApp.WebClient.WebPages.Dispatcher.TechDetails.UnassignJob(sourceElement);
//LTDWebApp.WebClient.WebPages.Dispatcher.TechDetails.GetUnassignedJobs(wcgId, drcCommitdate, onSuccessDragUnassign, onFailureDrag);
////////////////////End for Dragging & droping Jobs from Technician to Unassigned////////////
}
if (progressEnable == true)
{
showProgress(techId.replace("tech", "")); ////////Showing the Progress Bar
}
}
}

Step 7:

function onSuccessDrag(Result)
{
var ddb = new $IG.DragDropBehavior();
ddb.set_defaultDropAction($IG.DragDropAction.Insert);
ddb.set_dragDropMode($IG.DragDropEffects.Move);
var obtblid = "parent"+techId;
var objTbl = document.getElementById(obtblid);
var objTbody = objTbl.getElementsByTagName("tbody")[0];
objTbl.setAttribute("cellpadding", "0");
objTbl.setAttribute("cellspacing", "0");
objTbl.setAttribute("frame", "box");
objTbl.setAttribute("className", "tblAssignParenttech");
var preRows = objTbody.rows.length;
for (j = 0; j <>
{
if (j != 0)
{
objTbody.removeChild(objTbody.rows[j]);
}
}
var objRow = document.createElement("tr");
var objTd = document.createElement("td");
var objDiv = document.createElement("div");
objRow.setAttribute("className", "tblAssignParenttechRow");
objDiv.setAttribute("className", "tblscrollAssign");
objDiv.setAttribute("id", "tech"+techId);
var len = Result.length;
for (i = 0; i <>
objSplit = Result[i].split("||");
jobId = objSplit[0];
JobInterval = objSplit[1];
JobMON = objSplit[2];
var objchildjobDiv = document.createElement("div");
objchildjobDiv.setAttribute("id", jobId);
var objchildTbl = document.createElement("table");
var objchildTblBody = document.createElement("tbody");
objchildTbl.setAttribute("border", "0");
objchildTbl.setAttribute("width", "100%");
objchildTbl.setAttribute("cellpadding", "3");
objchildTbl.setAttribute("cellspacing", "1");
objchildTbl.setAttribute("className", "liBorder");
var objchildRow = document.createElement("tr");
var objchildTd = document.createElement("td");
objchildTd.setAttribute("className", "borderstyle");
var objchildTd1 = document.createElement("td");
objchildTd.innerText = JobInterval;
objchildTd1.innerText = JobMON;
objchildRow.appendChild(objchildTd);
objchildRow.setAttribute("ondblclick", "javscript:showJob(this);");
objchildRow.appendChild(objchildTd1);
objchildTblBody.appendChild(objchildRow);
objchildTbl.appendChild(objchildTblBody);
objchildjobDiv.appendChild(objchildTbl);
objDiv.appendChild(objchildjobDiv);
ddb.addSourceElement(objchildjobDiv);
}
objTd.appendChild(objDiv);
objRow.appendChild(objTd);
objTbody.appendChild(objRow);
ddb.set_defaultDropAction($IG.DragDropAction.Insert);
ddb.addTargetElement($get("DragUnassign"), true);
ddb.addTargetElement($get("tech" + techId), true);
ddb.get_events().addDropHandler(dropHandler);
hidemodalProgress();
}


Step 8:

Once the request is succeed with above method. I am generating the client side table with array data using javascript.

function onSuccessDrag(Result)
{
var ddb = new $IG.DragDropBehavior();
ddb.set_defaultDropAction($IG.DragDropAction.Insert);
ddb.set_dragDropMode($IG.DragDropEffects.Move);
var obtblid = "parent"+techId;
var objTbl = document.getElementById(obtblid);
var objTbody = objTbl.getElementsByTagName("tbody")[0];
objTbl.setAttribute("cellpadding", "0");
objTbl.setAttribute("cellspacing", "0");
objTbl.setAttribute("frame", "box");
objTbl.setAttribute("className", "tblAssignParenttech");
var preRows = objTbody.rows.length;
for (j = 0; j <>
{
if (j != 0)
{
objTbody.removeChild(objTbody.rows[j]);
}
}
var objRow = document.createElement("tr");
var objTd = document.createElement("td");
var objDiv = document.createElement("div");
objRow.setAttribute("className", "tblAssignParenttechRow");
objDiv.setAttribute("className", "tblscrollAssign");
objDiv.setAttribute("id", "tech"+techId);
var len = Result.length;
for (i = 0; i <>
objSplit = Result[i].split("||");
jobId = objSplit[0];
JobInterval = objSplit[1];
JobMON = objSplit[2];
var objchildjobDiv = document.createElement("div");
objchildjobDiv.setAttribute("id", jobId);
var objchildTbl = document.createElement("table");
var objchildTblBody = document.createElement("tbody");
objchildTbl.setAttribute("border", "0");
objchildTbl.setAttribute("width", "100%");
objchildTbl.setAttribute("cellpadding", "3");
objchildTbl.setAttribute("cellspacing", "1");
objchildTbl.setAttribute("className", "liBorder");
var objchildRow = document.createElement("tr");
var objchildTd = document.createElement("td");
objchildTd.setAttribute("className", "borderstyle");
var objchildTd1 = document.createElement("td");
objchildTd.innerText = JobInterval;
objchildTd1.innerText = JobMON;
objchildRow.appendChild(objchildTd);
objchildRow.setAttribute("ondblclick", "javscript:showJob(this);");
objchildRow.appendChild(objchildTd1);
objchildTblBody.appendChild(objchildRow);
objchildTbl.appendChild(objchildTblBody);
objchildjobDiv.appendChild(objchildTbl);
objDiv.appendChild(objchildjobDiv);
ddb.addSourceElement(objchildjobDiv);
}
objTd.appendChild(objDiv);
objRow.appendChild(objTd);
objTbody.appendChild(objRow);
ddb.set_defaultDropAction($IG.DragDropAction.Insert);
ddb.addTargetElement($get("DragUnassign"), true);
ddb.addTargetElement($get("tech" + techId), true);
ddb.get_events().addDropHandler(dropHandler);
hidemodalProgress();
}























Tuesday, May 19, 2009

ResizableControlExtender in Ajax

Asp.Net Ajax offers a ResizableControlExtender to resize the any element in the webpages. Please follow the below steps to create the Resizablecontrolextender for the panel.

Step 1:
Create Ajax enabled website.

Step 2:

Now go to the solution explorer and add the Ajaxcontroltoolkit.dll in the root directory.

Step 3:

Also add the Ajaxcontroltoolkit.dll in the toolbox to get the control.

Step 4:

Create CSS for HandleCssClass and ResizableCssClass for the control attribute.

<style type="text/css">
.handle
{
width:10px;
height:10px;
background-color:#aaccee;
}
.resizing
{
padding:0px;
border-style:solid;
border-width:1px;
border-color:#aaccee;
cursor:se-resize;
}
</style>



Step 4:

Create one panel with the some paragraph document.

<asp:Panel ID="Panel1" runat="server" Style="width: 300px; height: 200px;">
<asp:Label ID="image1" runat="server" Text="ASP.NET AJAX offers you Resizable Extender Control. ResizableControl is an extender that attaches to any element on a web page and allows the user to resize that control with a handle that attaches to lower-right corner of the control. The resize handle lets the user resize the element as if it were a window.">
</asp:Label>
</asp:Panel>

Step 5:

Create the ResizableControlExtender and link the panel.

<cc1:resizablecontrolextender ID="ResizableControlExtender1"
runat="server" TargetControlID="Panel1" HandleCssClass="handle" ResizableCssClass="resizing" MaximumHeight="400" MaximumWidth="500"
MinimumHeight="100" MinimumWidth="100" HandleOffsetX="5" HandleOffsetY="5" />

Monday, May 18, 2009

calling WCF Service method from javascript

here am speaking about the how wcf service method will call in the clientside using javascript. please find the below examples.

Before starting the code please select the template called Ajax enabled wcf service.

then call the method in the javascript.


ASPX with javascript.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function getValue()
{
AjaxWCF.DoWork(onSucess,onFailure)
}
function onSucess(result)
{
alert(result);
}
function onFailure(result)
{
alert(result);
}
</script>
</head>
<body onload="getValue();">
<form id="form1" runat="server">
<asp:ScriptManager ID="script" runat="server">
<Services>
<asp:ServiceReference Path="~/AjaxWCF.svc" />
</Services>
</asp:ScriptManager>
</form>
</body>
</html>

AjaxWCF.svc File


using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

namespace Xmlhttp
{
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class AjaxWCF
{
// Add [WebGet] attribute to use HTTP GET
[OperationContract]
public string DoWork()
{
// Add your operation implementation here
return "Hi bala";
}
// Add more operations here and mark them with [OperationContract]
}
}

Access a control on the Content Page from a MasterPage using JavaScript

If you have a control on the control page, which has to be accessed in the master page using JavaScript, then here how to do so.

on the content page. create a text box has given below.

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Panel ID="panelContent" GroupingText="ContentPage Controls" runat="server">
<asp:TextBox ID="txtContent" runat="server"></asp:TextBox>
</asp:Panel>
</asp:Content>

Now access and control the page text box "txtContent" from the master pages.

<head runat="server">
<title></title>
<script type="text/javascript">
function accessControlContentPage() {
var txtCont = document.getElementById('<%= Page.Master.FindControl("ContentPlaceHolder1").FindControl("txtContent").ClientID %>');
txtCont.value = "I got populated using Master Page";
}
</script>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
</head>

Thursday, May 14, 2009

Calling Webservice through Ajax with javascript

In modern way of calling the web service through the JavaScript.

Aspx page

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

<script type="text/javascript">
function OnLookup()
{
var stb = document.getElementById("txt1");
Xmlhttp.call.HelloWorld1(stb.value, OnLookupComplete);
}
function OnLookupComplete(result)
{
var res = document.getElementById("txtHint");
res.innerHTML = "<b>" + result + "</b>";
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="script" runat="server">
<Services>
<asp:ServiceReference Path="~/call.asmx" />
</Services>
</asp:ScriptManager>
First Name:<input type="text" id="txt1" onkeyup="OnLookup();">
<span id="txtHint"></span>
</div>
</form>
</body>
</html>


webservice
namespace Xmlhttp
{
///
/// Summary description for call
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class call : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
string value = "1";// HttpContext.Current.Request.QueryString["value"];
Dictionary objDictionary = new Dictionary();
if (HttpRuntime.Cache["out"] != null)
{
objDictionary = (Dictionary)HttpRuntime.Cache["out"];
if (!objDictionary.ContainsKey(value))
{
objDictionary.Add(value, value + "out");
}
}
else
{
objDictionary.Add(value, value + "out");
}
HttpRuntime.Cache["out"] = objDictionary;
return objDictionary[value];
}
[WebMethod]
public string HelloWorld1(string value)
{
return value;
}
}
}

Accessing webservice from javascript using XML HTTp Activex

Define:

XML http is a active X object to enable the browser to sending the request and receiving the response asynchronously.

Example:

Aspx Section


<html>
<head>
<script type="text/javascript">
var xmlHttp=null;
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
try
{// Firefox, Opera 8.0+, Safari, IE7
xmlHttp=new XMLHttpRequest();
}
catch(e)
{// Old IE
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
}
var url = "http://localhost:2735/call.asmx?op=HelloWorld";
//var getValue = document.getElementById("txt1");
//url = url + "&value='" + getValue.value + "'";

xmlHttp.onreadystatechange = output;
xmlHttp.open("GET",url,true);
xmlHttp.send();
function output() {
if (xmlHttp.readyState == 4)
{
xmlHttp.open("POST", "http://localhost:2735/call.asmx/HelloWorld", false);
xmlHttp.send();
document.getElementById("txtHint").innerHTML = xmlHttp.responseText;
}
}
}
</script>
</head>
<body>
<form>
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form><p>Suggestions: <span id="txtHint"></span></p> </body>
</html>

Webservice Section


namespace Xmlhttp
{
///
/// Summary description for call
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class call : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
string value = "1";// HttpContext.Current.Request.QueryString["value"];
Dictionary objDictionary = new Dictionary();
if (HttpRuntime.Cache["out"] != null)
{
objDictionary = (Dictionary)HttpRuntime.Cache["out"];
if (!objDictionary.ContainsKey(value))
{
objDictionary.Add(value, value + "out");
}
}
else
{
objDictionary.Add(value, value + "out");
}
HttpRuntime.Cache["out"] = objDictionary;
return objDictionary[value];
}
[WebMethod]
public string HelloWorld1(string value)
{
return value;
}
}
}