admin管理员组文章数量:1387303
I need to call server side method in code behind file from javascript. Yes i know ajax is the best way to achieve this. But i am not able to use ajax bcoz i exported excel file and get download in server side method. In ajax request we not are able to download/upload files. So kindly suggest any other way to call server side method in code behind from client side. I am also able to achieve this using web service. But i need the functionality in code behind file. I need the functionality like MVC form, in mvc form we are able to give control and action name and make form submit.
I need to call server side method in code behind file from javascript. Yes i know ajax is the best way to achieve this. But i am not able to use ajax bcoz i exported excel file and get download in server side method. In ajax request we not are able to download/upload files. So kindly suggest any other way to call server side method in code behind from client side. I am also able to achieve this using web service. But i need the functionality in code behind file. I need the functionality like MVC form, in mvc form we are able to give control and action name and make form submit.
Share Improve this question asked Jun 24, 2014 at 13:22 Sunil PrabakarSunil Prabakar 4421 gold badge5 silver badges19 bronze badges 2- 1 What is "bcoz" and does your shift key work? – epascarello Commented Jun 24, 2014 at 13:25
- So make a call to a hidden iframe. – epascarello Commented Jun 24, 2014 at 13:26
1 Answer
Reset to default 4Add following HTML on page:
<asp:ScriptManager ID='ScriptManager1' runat='server' EnablePageMethods='true' />
<asp:Button ID=”btnSave” runat=”server” Text=”Save” OnClientClick=”return CodeBehindMethodCall();” />
Now time to adjust our code behind so we can call it from JavaScript, we need to use System.Web.Services so add it in our code behind file
using System.Web.Services;
Whatever method we need to call from JavaScript, add WebMethodattribute to that method and that will easily be called by javaScript
[WebMethod]
public String ConvertDataTabletoString()
{
// your code
}
Now we will call ConvertDataTabletoString from JavaScript, so add the following JavaScript to the page:
function CodeBehindMethodCall()
{
pageName.ConvertDataTabletoString();
}
As you can see we have not used web service but we changed a method to web method so it can be called from JavaScript but without converting a method into web method we can not call any code behind method from JavaScript.
This is how its done.
本文标签: cNeed to call code behind method from Javascript without using ajax in aspnetStack Overflow
版权声明:本文标题:c# - Need to call code behind method from Javascript without using ajax in asp.net - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744499786a2609254.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论