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
.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742409746a4438572.html
评论列表(0条)