How to call code behind method in JavaScript in C# and VS2010?
来源:互联网 发布:c语言生命游戏 编辑:程序博客网 时间:2024/05/16 19:11
转自:http://www.dotnetfunda.com/articles/article1525-how-to-call-code-behind-method-in-javascript-in-csharp-and-vs2010.aspx
How to call code behind method in JavaScript in C# and VS2010
Introduction
Certain requirements requires us to communicate with code behind code, here is how you can access code behind function in java script.
1) Createwebsite in vs2010
2) Add Ajax.dll into Bin folder of website.
you can use http://www.dotnetfunda.com/UserFiles/ArticlesFiles/Mehulthakkar1_Articles_633978174491924922_DemoAjaxApp.zip
to download Ajax.dll
3) Add Using Ajax; to your code
4)Add Ajax.Utility.RegisterTypeForAjax(this.GetType());to page load.
5) Add Ajax.JavascriptMethod() just above the function you need to call in javascript.
Ex:
[Ajax.JavascriptMethod()]
public string ReturnString()
{
return "Hi this sample test";
}
6) In aspx, just call the function.
Ex:
<script language="javascript"type="text/javascript">
functiontest1() {
window.alert(ReturnString());
}
</script>
<asp:ButtonID="Button1"runat="server"Text="Button"OnClientClick="test1()"/>
Thanks for reading! Do let me know your feedback or comment.
- How to call code behind method in JavaScript in C# and VS2010?
- How to call c++ exported method and classes in c#
- 【转】How to call c++ exported method and classes in c#
- How to attach behavior in code behind (Silverlight 3)
- How to Call C# DLL in Delphi7
- WPF: Animations in XAML and code-behind
- WPF: Animations in XAML and code-behind
- How to handle exception in managed code and unmanaged code
- How to handle exception in managed code and unmanaged code
- Js AJAX call code behind Web Method
- Call and Apply in JavaScript
- 通过HttpHandler和属性用Javascript调用C#方法(Using a HttpHandler and Attributes to call C# methods in Javascript)
- How to write the fast code/ high performance in C#
- How To Call Run() Method of the Microsoft Script Control in C++
- How to Call Back In Com ?
- How to call API in Java
- How to call Matlab function in C++
- How to call stored procedure in Hibernate
- 蝴蝶兰与鳞托菊
- malloc/free 和 new/delete
- 淡淡的微笑,静悄悄地过
- 淘宝笔试
- 我原来如此
- How to call code behind method in JavaScript in C# and VS2010?
- 断想
- WinForm下Grid单元格的合并讨论摘录【2】
- 紫薇花开的季节(二)
- 做饭记
- Android Location在GPS中的应用(二)
- 那时,我们正年轻
- android2.2源码编译过程遇到的问题
- 薄荷花开