Click here to Skip to main content
15,897,187 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questionweb stats recommendations Pin
Jassim Rahma19-Oct-12 2:52
Jassim Rahma19-Oct-12 2:52 
AnswerRe: web stats recommendations Pin
code-frog19-Oct-12 18:11
professionalcode-frog19-Oct-12 18:11 
Questionhow can i add two page route in mvc? Pin
mhd.sbt19-Oct-12 2:32
mhd.sbt19-Oct-12 2:32 
AnswerRe: how can i add two page route in mvc? Pin
Deflinek19-Oct-12 2:50
Deflinek19-Oct-12 2:50 
GeneralRe: how can i add two page route in mvc? Pin
mhd.sbt19-Oct-12 6:25
mhd.sbt19-Oct-12 6:25 
AnswerRe: how can i add two page route in mvc? Pin
Mayank_Gupta_24-Oct-12 22:51
professionalMayank_Gupta_24-Oct-12 22:51 
QuestionAjax page method call during form validation Pin
Jay Royall18-Oct-12 22:43
Jay Royall18-Oct-12 22:43 
AnswerRe: Ajax page method call during form validation Pin
Richard Deeming19-Oct-12 1:44
mveRichard Deeming19-Oct-12 1:44 
You could try taking the "A" out of "AJAX".

Add the script below, and then change your PageMethods.EmailAddressIsValid call to SyncPageMethods.EmailAddressIsValid.

C#
Type.registerNamespace("System.Net");

System.Net.XMLHttpSyncExecutor = function()
{
   if (arguments.length !== 0) { throw Error.parameterCount(); }
   System.Net.XMLHttpSyncExecutor.initializeBase(this);
};

System.Net.XMLHttpSyncExecutor.prototype =
{
   executeRequest: function()
   {
      if (arguments.length !== 0) { throw Error.parameterCount(); }

      var webRequest = this.get_webRequest();
      if (this._started) { throw Error.invalidOperation(String.format(Sys.Res.cannotCallOnceStarted, "executeRequest")); }
      if (null === webRequest) { throw Error.invalidOperation(Sys.Res.nullWebRequest); }

      var body = webRequest.get_body();
      var headers = webRequest.get_headers();

      this._xmlHttpRequest = new XMLHttpRequest();
      this._xmlHttpRequest.onreadystatechange = this._onReadyStateChange;

      var verb = this._webRequest.get_httpVerb();
      this._xmlHttpRequest.open(verb, this._webRequest.getResolvedUrl(), false);

      if (headers)
      {
         for (var header in headers)
         {
            var val = headers[header];
            if (typeof(val) !== "function")
            {
               this._xmlHttpRequest.setRequestHeader(header, val);
            }
         }
      }

      if ("post" === verb.toLowerCase())
      {
         if (null === headers || !headers["Content-Type"])
         {
            this._xmlHttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
         }

         if (!body)
         {
            body = "";
         }
      }

      this._xmlHttpRequest.send(body);

      if (null !== this._xmlHttpRequest)
      {
         // Firefox doesn't raise "onreadystatechange" events for sync requests:
         this._responseAvailable = true;
         webRequest.completed(Sys.EventArgs.Empty);
         this._xmlHttpRequest.onreadystatechange = Function.emptyMethod;
         this._xmlHttpRequest = null;
      }
   }
};

System.Net.XMLHttpSyncExecutor.registerClass("System.Net.XMLHttpSyncExecutor", Sys.Net.XMLHttpExecutor);

System.Net.WebServiceSyncProxy = function()
{
   if (arguments.length !== 0) { throw Error.parameterCount(); }
   System.Net.WebServiceSyncProxy.initializeBase(this);
};

System.Net.WebServiceSyncProxy.prototype =
{
   _invokeSync: function(servicePath, methodName, useGet, params)
   {
      /// <param name="servicePath" type="String"></param>
      /// <param name="methodName" type="String"></param>
      /// <param name="useGet" type="Boolean" optional="true"></param>
      /// <param name="params" mayBeNull="true" optional="true"></param>
      var e = Function._validateParams(arguments, [
         {name: "servicePath", type: String},
         {name: "methodName", type: String},
         {name: "useGet", type: Boolean, optional: true},
         {name: "params", mayBeNull: true, optional: true}
      ]);
      if (e) { throw e; }

      return System.Net.WebServiceSyncProxy.invokeSync(servicePath, methodName, useGet, params);
   }
};

System.Net.WebServiceSyncProxy.invokeSync = function(servicePath, methodName, useGet, params)
{
   /// <param name="servicePath" type="String"></param>
   /// <param name="methodName" type="String"></param>
   /// <param name="useGet" type="Boolean" optional="true"></param>
   /// <param name="params" mayBeNull="true" optional="true"></param>
   var e = Function._validateParams(arguments, [
      {name: "servicePath", type: String},
      {name: "methodName", type: String},
      {name: "useGet", type: Boolean, optional: true},
      {name: "params", mayBeNull: true, optional: true}
   ]);
   if (e) { throw e; }

   var request = new Sys.Net.WebRequest();
   request.set_executor(new System.Net.XMLHttpSyncExecutor());

   request.get_headers()["Content-Type"] = "application/json; charset=utf-8";
   if (!params) { params = {}; }

   var urlParams = params;
   if (!useGet || !urlParams) { urlParams = {}; }

   request.set_url(Sys.Net.WebRequest._createUrl(servicePath + "/" + encodeURIComponent(methodName), urlParams));

   var body = null;
   if (!useGet)
   {
      body = Sys.Serialization.JavaScriptSerializer.serialize(params);
      if (body === "{}") { body = ""; }
   }

   request.set_body(body);

   var result = null;
   request.add_completed(onComplete);
   request.invoke();

   function onComplete(response, eventArgs)
   {
      if (response.get_responseAvailable())
      {
         var statusCode = response.get_statusCode();

         try
         {
            var contentType = response.getResponseHeader("Content-Type");
            if (contentType.startsWith("application/json"))
            {
               result = response.get_object();
            }
            else if (contentType.startsWith("text/xml"))
            {
               result = response.get_xml();
            }
            else
            {
               result = response.get_responseData();
            }
         }
         catch (ex)
         {
         }

         var error = response.getResponseHeader("jsonerror");
         var errorObj = (error === "true");
         if (errorObj)
         {
            if (result)
            {
               result = new Sys.Net.WebServiceError(false, result.Message, result.StackTrace, result.ExceptionType);
            }
         }
         else if (contentType.startsWith("application/json"))
         {
            if (!result || typeof(result.d) === "undefined")
            {
               throw Sys.Net.WebServiceProxy._createFailedError(methodName,
                  String.format(Sys.Res.webServiceInvalidJsonWrapper, methodName));
            }
            result = result.d;
         }
         if (statusCode < 200 || statusCode >= 300 || errorObj)
         {
            var err;
            if (result && errorObj)
            {
               err = result.get_exceptionType() + "-- " + result.get_message();
            }
            else
            {
               err = response.get_responseData();
            }

            throw Sys.Net.WebServiceProxy._createFailedError(methodName, String.format(Sys.Res.webServiceFailed, methodName, err));
         }
      }
      else
      {
         var msg;
         if (response.get_timedOut())
         {
            msg = String.format(Sys.Res.webServiceTimedOut, methodName);
         }
         else
         {
            msg = String.format(Sys.Res.webServiceFailedNoMsg, methodName);
         }

         throw Sys.Net.WebServiceProxy._createFailedError(methodName, msg);
      }
   }

   return result;
};

System.Net.WebServiceSyncProxy.generateSyncProxy = function(proxy, proxyName, syncProxyName)
{
   /// <param name="proxy"></param>
   /// <param name="proxyName" type="String"></param>
   /// <param name="syncProxyName" type="String" optional="true"></param>
   var e = Function._validateParams(arguments, [
      {name: "proxy"},
      {name: "proxyName", type: String},
      {name: "syncProxyName", type: String, optional: true}
   ]);
   if (e) { throw e; }

   if (proxy && proxy.prototype)
   {
      if (!syncProxyName || 0 === syncProxyName.length)
      {
         syncProxyName = proxyName + "Sync";
      }

      var item;
      var foundMethods = [];
      for (var key in proxy.prototype)
      {
         if ("string" === typeof(key) && "_" !== key.charAt(0) && "constructor" !== key && !key.startsWith("get_") && !key.startsWith("set_"))
         {
            item = proxy.prototype[key];
            if ("function" === typeof(item) && 3 <= item.length)
            {
               item = item.toString();
               item = item.replace(/function[^\(]*\(/g, "function(");
               item = item.replace(/\(succeededCallback,\s*failedCallback,\s*userContext\)/g, "()");
               item = item.replace(/,\s*succeededCallback,\s*failedCallback,\s*userContext\)/g, ")");
               item = item.replace("this._invoke(this._get_path(),", "System.Net.WebServiceSyncProxy.invokeSync(" + proxyName + ".get_path(),");
               foundMethods.push(syncProxyName + "." + key + "=" + item);
            }
         }
      }

      if (0 !== foundMethods.length)
      {
         eval(syncProxyName + "=function(){if(arguments.length!==0){throw Error.parameterCount();}throw Error.notImplemented();};");
         for (var i = 0; i < foundMethods.length; i++)
         {
            eval(foundMethods[i]);
         }
      }
   }
};

System.Net.WebServiceSyncProxy.registerClass("System.Net.WebServiceSyncProxy", Sys.Net.WebServiceProxy);

Sys.Application.add_init(function()
{
   if (window.PageMethods)
   {
      System.Net.WebServiceSyncProxy.generateSyncProxy(window.PageMethods, "PageMethods", "SyncPageMethods");
   }
});


C#
function ValidateForm() {

   pageIsValid = true;

   if (!SyncPageMethods.EmailAddressIsValid(document.getElementById('<%= txtNewMemberEmailAddress.ClientID %>').value))
   {
      document.getElementById('<%= imgNewMemberEmailAddress.ClientID %>').src = "/Images/cross.png";
      emailAddressMessage = 'The email address you have entered is already in use';
      pageIsValid = false;
   }
   else
   {
      document.getElementById('<%= imgNewMemberEmailAddress.ClientID %>').src = "/Images/tick.png";
      emailAddressMessage = 'This field is valid';
   }

   ...

   return pageIsValid;
}




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


GeneralRe: Ajax page method call during form validation Pin
Jay Royall19-Oct-12 2:03
Jay Royall19-Oct-12 2:03 
GeneralRe: Ajax page method call during form validation Pin
BobJanova19-Oct-12 2:36
BobJanova19-Oct-12 2:36 
GeneralRe: Ajax page method call during form validation Pin
Richard Deeming19-Oct-12 8:03
mveRichard Deeming19-Oct-12 8:03 
AnswerRe: Ajax page method call during form validation Pin
BobJanova19-Oct-12 2:39
BobJanova19-Oct-12 2:39 
GeneralRe: Ajax page method call during form validation Pin
Jay Royall19-Oct-12 3:04
Jay Royall19-Oct-12 3:04 
AnswerRe: Ajax page method call during form validation Pin
jkirkerx19-Oct-12 10:08
professionaljkirkerx19-Oct-12 10:08 
Questionhow we can add source code in our running projects which given by code project website Pin
ashvin sharma18-Oct-12 22:40
ashvin sharma18-Oct-12 22:40 
AnswerRe: how we can add source code in our running projects which given by code project website Pin
Richard MacCutchan18-Oct-12 23:28
mveRichard MacCutchan18-Oct-12 23:28 
GeneralRe: how we can add source code in our running projects which given by code project website Pin
ashvin sharma19-Oct-12 1:52
ashvin sharma19-Oct-12 1:52 
GeneralRe: how we can add source code in our running projects which given by code project website Pin
Richard MacCutchan19-Oct-12 2:20
mveRichard MacCutchan19-Oct-12 2:20 
Questionhelp plx Pin
Muddassir Husain Awan18-Oct-12 20:35
Muddassir Husain Awan18-Oct-12 20:35 
AnswerRe: help plx Pin
Richard MacCutchan18-Oct-12 23:26
mveRichard MacCutchan18-Oct-12 23:26 
GeneralRe: help plx Pin
Pete O'Hanlon18-Oct-12 23:43
mvePete O'Hanlon18-Oct-12 23:43 
GeneralRe: help plx Pin
Richard MacCutchan19-Oct-12 0:09
mveRichard MacCutchan19-Oct-12 0:09 
GeneralRe: help plx Pin
jkirkerx19-Oct-12 10:37
professionaljkirkerx19-Oct-12 10:37 
AnswerRe: help plx Pin
J4amieC19-Oct-12 2:02
J4amieC19-Oct-12 2:02 
GeneralRe: help plx Pin
Deflinek19-Oct-12 2:58
Deflinek19-Oct-12 2:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.