Call C# method from JavaScript with parameter -
i want call c# method parameter javascript. possible, if remove parameter s
of method <% showdetail(); %>
function showdetail(kurz) { string s = kurz.tostring(); <% showdetail(s); %>; }
c# methods test:
public void showdetail(string s) { label_test.text = s.tostring(); } public void showdetail() { label_test.text = ""; }
it works fine without parameter s
variable compiler error:
cs0103: name 's' not exist in current context
i have tried
showdetail(object s){....}
and also
showdetail(string s){....}
but not work.
create web method. that's easy , neat way of calling c# methods javascript. can call method using jquery ajax. see below example webmethod.
[webmethod] public static string registeruser(string s) { //do stuff return stringresult; }
and call method using jquery ajax. can pass parameters also. given below
function showdetail(kurz) { string sparam = kurz.tostring(); $.ajax({ type: "post", url: "pagename.aspx/methodname", data: "{s:sparam}", // passing parameter contenttype: "application/json; charset=utf-8", datatype: "json", success: function(retvalue) { // return value from.net method } }); }
Comments
Post a Comment