c# - How to call page method without page-reload? - Stack Overflow

It might be seems to be FAQ. but I got Something in my mind and let me explain that.I search an test m

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:

  1. Jquery With Ajax
  2. Webform_Docallback
  3. 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!

  1. didn't have access to this Object
  2. 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:

  1. Jquery With Ajax
  2. Webform_Docallback
  3. 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!

  1. didn't have access to this Object
  2. didn't have access to Page-Controls

So How to solve these issue's?

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 1
  • 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
Add a ment  | 

3 Answers 3

Reset to default 3

For 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

相关推荐

  • c# - How to call page method without page-reload? - Stack Overflow

    It might be seems to be FAQ. but I got Something in my mind and let me explain that.I search an test m

    4小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信