Call C# function in javascript

PagodNaUtak
PagodNaUtak used Ask the Experts™
on
How can you call a C# function in javascript
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Software Engineer
Top Expert 2009
Commented:
Use page methods, check:
http://visualstudiomagazine.com/articles/2007/08/28/creating-and-consuming-aspnet-ajax-page-methods.aspx

basically your C# fucntion is a web method.

U can use web methods..I will show u an example.
(Below function will written in codebehind)
[WebMethod]
public static string MyMethod(string name)
{
    return "Hai " + name;
}

You can call this MyMethod in javascript like this.

<script>
    function test(){
        alert(PageMethods.MyMethod("Johns"));
    }
</script>
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Miguel OzSenior Software Engineer
Top Expert 2009

Commented:
vivekpv10, I already suggested pageMethods in my previous comment and the posted link already contained a sample. Thanks
Hai mas_oz2003:This question  is not logical one.The question having only one solution.ie:use WebMethods.So i posted that answer.I explained that with a simple example and also with a link that also providing code sample.I think i done nothing wrong with that.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial