How to call code behind method in JavaScript in C# and VS2010?
2012-09-11 01:12
716 查看
转自: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
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:Button
ID="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
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:Button
ID="Button1"runat="server"Text="Button"OnClientClick="test1()"
/>
Thanks for reading! Do let me know your feedback or comment.
相关文章推荐
- How to call c++ exported method and classes in c#
- 【转】How to call c++ exported method and classes in c#
- In Javascript Class, how to call the prototype method.(three method)
- In Javascript Class, how to call the prototype method.(three method)
- 通过HttpHandler和属性用Javascript调用C#方法(Using a HttpHandler and Attributes to call C# methods in Javascript)
- How to invoke the method of managed bean and render view in JSF when we are outside the lifecycle of JSF
- Units Problem: How to read text size as custom attr from xml and set it to TextView in java code
- How to change the generated method stub code for C#
- How to get multiple select value both in javascript and php
- how to call javascript function in webview
- What is EPOLL? EPOLL vs Select call? And How to implement UDP server in Linux using EPOLL?
- How To Use the ODBC .NET Managed Provider in Visual C# .NET and Connection Strings
- Excel: How to run C# code behind with a click of a button on a Worksheet, without VBA code
- CodeProject - How to develop a screen saver in C#(翻译)
- how to blend VB and C# in one project
- How to compile and debug VLC player source code in eclipse IDE on Ubuntu 10.04 (lucid)?
- Android: How to download the latest zip Android Source Code easily and using it in Intellij
- How to handle exception in managed code and unmanaged code
- Units Problem: How to read text size as custom attr from xml and set it to TextView in java code
- This program is used to explain how PCA works and the idea behind the method.