English 中文(简体)
AJAX/Javascript PageMethod.FunctionName, Trying to made this code reusable in ASP.NET
原标题:

I have implemented AJAX for calling server side function using client side function call i.e Calling server side function using javascript tag by using PageMethod in javascript.

I have few question regarding the same implementation.

      function OnBlurCall()
      {
        chk(ControlId, SpanMsgId, FunctionName)// where all these parameters are obtained from programmer.
      }

   function chk(ControlId,SpanMsgId, FunctionName)
   {
     PageMethods.FunctionName(ControlId.value,onSuccess,onFail,SpanMsgId); // I want to replace actual value of FunctionName i.e Something given below
     PageMethods.CheckUserNameAvailability(ControlId.value,onSuccess,onFail,SpanMsgId);
   }

   function onSuccess(result,MsgId,methodname)
    {
        MsgId.innerHTML=result;
    }

    function onFail(error,MsgId,methodname)
    {
            MsgId.innerHTML=error;
    }

Ques 1. How many parameters can i add to this function. Is it there some limit that i can send only 3 parameters. Please give some details how it is working.

Ques 2. I want to make above code reusabe in javascript such that I add all the 3 functions in master page. But the problem is that i can add two functions into javascript at this time. But for adding 3rd function i have to send function name also as a parameter.

PageMethods.FunctionName(ControlId.value,onSuccess,onFail,SpanMsgId);

This FunctionName will be the name of server side function that a developer want to call. Can i do this. ?

最佳回答

You can generically check for arguments; while in the function method, the arguments array has a list of all the arguments for that method. Check this out: https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Functions_and_function_scope/Arguments

To invoke dynamically, you could consider using the WebServiceProxy: http://www.asp.net/ajax/documentation/live/clientreference/Sys.Net/WebServiceProxyClass/WebServiceProxyInvokeMethod.aspx

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签