Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
This is my method .i want to call this method to javascript,how to do it.

any one can help me???

C#
public static DataSet getCitycode(string Citycode )
{

   string sql = "SELECT  Citycode  FROM tblCityDetails WHERE Citycode  ='"+ Citycode +"'";
   DataSet Sector = SQLTrans.executeQuery(sql);
   return Sector;
}
Posted

You cannot. Not that it's just impossible, the whole idea simply makes no sense. This is not how things work. This methods is executed on server side, and JavaScript — on client side.

You need to learn the basics of HTTP, Web, .NET, and only then ASP.NET. You apparently did not get it yet. Not to worry, you will learn it:
http://www.asp.net/get-started[^].

—SA
 
Share this answer
 
v2
Comments
[no name] 11-Mar-13 23:57pm    
My 5!
Sergey Alexandrovich Kryukov 12-Mar-13 0:05am    
Thank you, Pranit.
—SA
If your method is in code behind file means aspx.cs file then you can call that method using jQuery like
$(document).ready(function () {
     $.ajax({
         type: 'POST',
         url: 'Default.aspx/MethodInAspxFile',
         data: "{'param':'value'}",
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (msg) {
             alert(msg);
             //do your task
         }
     });
 });


and method in your aspx.cs file looks like

//using System.Web.Services; add this namespace in aspx.cs file
[WebMethod]
public static DataSet MethodInAspxFile(string param)
{
    DataSet ds = new DataSet();
    //preform your operation here
    return ds;
}
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900