开发者

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,开发者_StackOverflow中文版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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜