When I have started work on ajax. I used to passed parameters in the url while calling server side method through ajax call. But problem was that when we send value with Hash(#). It was not sending whole value to server side.It was sending only value before hash(#). Than I have found another way to send parameter to sever side.We can directly call server side method and pass parameter through ajax call.
Write this function on client side.
function SendServer()
{
// var sVal = $("#txtName").val();
var sVal = "Red";
$.ajax(
{
type: "POST",
url: "Customer.aspx/GetValue",
data: "{param1: " + "'" + sVal + "'" + " }",
//data: "{'param1': 1}",
contentType: "application/json; charset=utf-8",
dataType: "json",
timeout:5000,
success: function (msg)
{
alert(msg);
// $('#Rslt').text(msg);
},
error:function(msg1)
{
alert(msg1);
// $('#Rslt').text("Some error has been occurred.");
}
});
}
And on server side define a static method with WebMethod attribute. Add a name space System.Web.Services
[WebMethod]
public static string GetValue(string param1)
{
return "Call Server Side method through ajax call and pass parameter :" + param1;
}
One thing that you have to remember parameter name should be same on both side.Just like the above example I have used param1 both side.
You can download the sample code from here.
http://www.box.net/shared/ivv6jhk1gm
Subscribe to:
Post Comments (Atom)
Followers
Link
Labels
Agille
(3)
Angular 2
(96)
Architecture
(7)
ASP .Net
(30)
C#/VB .Net
(161)
Entityframework
(11)
General
(33)
Git
(2)
Hosting
(2)
HTML
(4)
Interview
(12)
Interview-Agile
(1)
Interview-Angular
(25)
Interview-ASP .Net
(3)
Interview-C#
(16)
Interview-JavaScript
(1)
Interview-MVC
(30)
Interview-SQL Server
(4)
Interview-WCF
(2)
Islam
(6)
Java Script
(37)
JQuery
(1)
MVC
(53)
NodeJS
(1)
Puzzles
(1)
React-Native
(3)
Security
(1)
Shayri
(10)
SQL Server
(41)
VC++
(5)
WCF
(21)
Web API
(27)
WPF
(21)
No comments:
Post a Comment