Hello Sir, I made one web service of named WebService in which GetTest, SetTest function which set and get GUID. Now i want to use this function in javascript in .aspx file. How i use this function in javascript. I put web service code below:-
[WebMethod]
public void SetTest(Guid id, string text)
{
this.Application.Add(id.ToString(), text);
}
[WebMethod]
public string GetTest(Guid id)
{
return this.Application[id.ToString()].ToString();
}
[WebMethod]
public Guid CreateNew()
{
return Guid.NewGuid();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
AND .ASPX CODE:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UsingWebService.aspx.cs" Inherits="UsingWebService" %>
<!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 runat="server">
<title>Using Web Service</title>
<script type="text/javascript" language="javascript">
debugger;
var txtGetTestID = '<%= this.txtGetTest.ClientID %>';
var txtSetTestID = '<%= this.txtSetTest.ClientID %>';
var _guid = null;
function GetNew()
{
//WebService.CreateNew(GetNewDone,OnError,null);
GetNewDone(WebService.CreateNew());
}
function GetNewDone(result)
{
_guid = result;
}
function SetTest()
{
WebService.SetTest(_guid,$get(txtSetTestID).value);
}
function GetTest()
{
//WebService.GetTest(_guid,GetTestDone,OnError ,null);
GetTestDone(WebService.GetTest(_guid));
}
function GetTestDone(result)
{
$get(txtGetTestID).value = result;
}
function OnError(ex)
{
alert('Error: '+ex._message);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblInput" Text="Input String" runat="server"></asp:Label>
<asp:TextBox ID="txtInput" runat="server"></asp:TextBox>
<br />
<asp:Label ID="lblResult" runat="server"></asp:Label>
<br />
<br />
<asp:Button ID="btnInvoke" Text="Invoke" runat="server"
onclick="btnInvoke_Click" />
</div>
<table>
<tr>
<td>
</td>
<td>
<asp:Button id="btnNew" runat="server" Text="New" OnClientClick="GetNew(); return false;" />
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtSetTest" runat="server" />
</td>
<td>
<asp:Button ID="btnSetTest" runat="server" Text="Set" OnClientClick="SetTest(); return false;" />
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtGetTest" runat="server" />
</td>
<td>
<asp:Button ID="btnGet" runat="server" Text="Get" OnClientClick="GetTest(); return false;" />
</td>
</tr>
</table>
</form>
</body>
</html>