admin管理员组文章数量:1336616
It might be seems to be FAQ. but I got Something in my mind and let me explain that. I search an test many way's for doing that and at the end I found these soultion:
- Jquery With Ajax
- Webform_Docallback
- Script Manager and UpdatePanel
so what I need is Something Like first solution, but also want to access to this
object and even page controls
. and Reason don't use the second and third solution is they call Page-Reload first and then call that method
. So that's what I Need!
Is there any solution? any tip's?
Additional Info :
I need something like: call Method by button_click
and go to the server side. in Server-Side call Wcf-Service and finally do something. (like binding grid datasources, change textbox values or etc).
Almost jQuery with Ajax
is what I need. but I have these problem with this way!
- didn't have access to this Object
- didn't have access to Page-Controls
So How to solve these issue's?
It might be seems to be FAQ. but I got Something in my mind and let me explain that. I search an test many way's for doing that and at the end I found these soultion:
- Jquery With Ajax
- Webform_Docallback
- Script Manager and UpdatePanel
so what I need is Something Like first solution, but also want to access to this
object and even page controls
. and Reason don't use the second and third solution is they call Page-Reload first and then call that method
. So that's what I Need!
Is there any solution? any tip's?
Additional Info :
I need something like: call Method by button_click
and go to the server side. in Server-Side call Wcf-Service and finally do something. (like binding grid datasources, change textbox values or etc).
Almost jQuery with Ajax
is what I need. but I have these problem with this way!
- didn't have access to this Object
- didn't have access to Page-Controls
Share Improve this question edited Aug 23, 2011 at 3:57 Rev asked Aug 21, 2011 at 9:54 RevRev 2,2758 gold badges45 silver badges77 bronze badges 1So How to solve these issue's?
- I'd go with jquery on this one. Phil Haack recently released this sweet addon to MVC for calling action methods from JS: haacked./archive/2011/08/18/… – Jamie Dixon Commented Aug 21, 2011 at 9:57
3 Answers
Reset to default 3For the first one
Create a WebMethod in the .cs file
[WebMethod]
public static string Foo()
{
//......
}
If you want to use session you should
[WebMethod(EnableSession = true)] or [WebMethod(true)]
public static string Foo()
{
//......
}
Then , invoke the webmothod by js
$.ajax({
type: "POST",
contentType: "application/json",
url: "WebForm1.aspx/Foo",
data: "{}",
dataType: "json",
success: function(){.......}
});
Hope it useful...
[WebMethod()]
[System.Web.Script.Services.ScriptMethod()]
public static void YourTaskNAme(Your Parameter)
{
// Yuor Code here
}
Update the script manager to have the following property EnablePageMethods="true"
finally use the javascript to call this method
PageMethods.YourTaskNAme(Your Parameter, OnMethodFinished);
function OnMethodFinished() {
alert('Call to function worked.')
}
You can bypass any logic you have inside your Page_Load
method by checking the ScriptManager.IsInAsyncPostBack
property with a ScriptManager
and UpdatePanel
.
本文标签: cHow to call page method without pagereloadStack Overflow
版权声明:本文标题:c# - How to call page method without page-reload? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742409746a2469546.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论