Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi all, I need to create a web service to pass the dataset to javascript function. I don't have that much idea in webservice.I wish to know the step by step process. Can anyone help to solve this out.
 
Thanks in advance.
 
arun
Posted 26-Jun-12 19:32pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
arun.m.mr at 27-Jun-12 4:24am
   
Thank you Vani Kulkarni.
Vani Kulkarni at 27-Jun-12 5:01am
   
Welcome arun!
arun.m.mr at 27-Jun-12 5:26am
   
<%@ Page Language="C#" %>
 
<%@ Import Namespace="System.Data" %>
 
<script runat="server">
[System.Web.Services.WebMethod]
 
[System.Web.Script.Services.ScriptMethod]
public static System.Data.DataTable MyMethod(int value)
{
return GetDataSet(value);
}
 
public static System.Data.DataTable GetDataSet(int value)
{
 
DataTable dt = new DataTable("Author");
DataRow dr;
dt.Columns.Add(new DataColumn("Id", typeof(Int32)));
dt.Columns.Add(new DataColumn("Author", typeof(string)));
 
for (int i = 0; i <= 10; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Author" + i.ToString();
dt.Rows.Add(dr);
}
for (int i = 20; i <= 40; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Author" + i.ToString();
dt.Rows.Add(dr);
}
 

DataView dv = new DataView(dt);
dv.RowFilter = "Id='" + value + "'";
 

 
return dv.Table;
}
 

 
</script>
 
<!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 id="Head1" runat="server">
<title>Untitled Page</title>
 
<script language="javascript" type="text/javascript">
function CallMyWebService()
{
WebService.MyMethod(1,OnRequestComplete);
}
function OnRequestComplete(result)
{
var str="";
for(var i = 0; i < result.rows.length; i++)

{
str+=result.rows[i].Author +"<br>";

}
document.getElementById('result').innerHTML=str;
}
</script>
 
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="scriptManger1" runat="server"
EnablePageMethods="true">

<asp:ServiceReference Path="~/WebService.asmx" />


<div id="result">
</div>
<input type="button" önclick="CallMyWebService();" id="myButton"
value="Call MyWebService" />
</div>
</form>
</body>
</html>
if you tried, you likely received some sort of circular reference serialization error to take advantage of this, you will need to add the following to your web.config:
 

 

 

<scripting>









</scripting>

 
I use the same code. But it is not working. Can u check it Vani.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 505
1 OriginalGriff 248
2 ChintanShukla 185
3 Richard Deeming 175
4 Bhavik_Patel 170
0 Sergey Alexandrovich Kryukov 8,688
1 OriginalGriff 7,237
2 CPallini 2,598
3 Richard MacCutchan 2,080
4 Abhinav S 1,888


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 27 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100