Explorar o código

2007-02-013 Igor Zelmanovich <[email protected]>

	* Page.cs: fixed exception handling on Callback at client.

svn path=/trunk/mcs/; revision=72775
Igor Zelmanovich %!s(int64=19) %!d(string=hai) anos
pai
achega
7dc14fae8e

+ 4 - 0
mcs/class/System.Web/System.Web.UI/ChangeLog

@@ -1,3 +1,7 @@
+2007-02-013 Igor Zelmanovich <[email protected]>
+
+	* Page.cs: fixed exception handling on Callback at client.
+
 2007-02-08  Marek Habersack  <[email protected]>
 
 	* Page.cs: Make sure to create specific cultures.

+ 17 - 4
mcs/class/System.Web/System.Web.UI/Page.cs

@@ -1872,13 +1872,26 @@ return true;
 		if (target == null)
 			throw new HttpException (string.Format ("Invalid callback target '{0}'.", callbackTarget));
 
+		string callbackEventError = String.Empty;
+		string callBackResult;
 		string callbackArgument = _requestValueCollection [CallbackArgumentID];
-		target.RaiseCallbackEvent (callbackArgument);
 
+		try {
+			target.RaiseCallbackEvent (callbackArgument);
+		}
+		catch (Exception ex) {
+			callbackEventError = String.Format ("e{0}", ex.Message);
+		}
+		
+		try {
+			callBackResult = target.GetCallbackResult ();
+		}
+		catch (Exception ex) {
+			return String.Format ("e{0}", ex.Message);
+		}
+		
 		string eventValidation = ClientScript.GetEventValidationStateFormatted ();
-		string callBackResult= target.GetCallbackResult ();
-
-		return String.Format ("{0}|{1}{2}", eventValidation == null ? 0 : eventValidation.Length, eventValidation, callBackResult);
+		return String.Format ("{0}{1}|{2}{3}", callbackEventError, eventValidation == null ? 0 : eventValidation.Length, eventValidation, callBackResult);
 	}
 
 	[BrowsableAttribute (false)]

+ 10 - 9
mcs/class/System.Web/resources/webform.js

@@ -134,8 +134,11 @@ function WebForm_DoCallback (id, arg, callback, ctx, errorCallback)
 
 function WebForm_ClientCallback (httpPost, ctx, callback, errorCallback)
 {
-	try {
-		var doc = httpPost.responseText;
+	var doc = httpPost.responseText;
+	if (doc.charAt(0) == "e") {
+		if ((typeof(errorCallback) != "undefined") && (errorCallback != null))
+			errorCallback(doc.substring(1), ctx);
+	} else {
 		var separatorIndex = doc.indexOf("|");
 		if (separatorIndex != -1) {
 			var validationFieldLength = parseInt(doc.substring(0, separatorIndex));
@@ -151,16 +154,14 @@ function WebForm_ClientCallback (httpPost, ctx, callback, errorCallback)
 					}
 					validationFieldElement.value = validationField;
 				}
-				callback (doc.substring(separatorIndex + validationFieldLength + 1), ctx);
-				return;
+				if ((typeof(callback) != "undefined") && (callback != null))
+					callback (doc.substring(separatorIndex + validationFieldLength + 1), ctx);
 			}
+		} else {
+			if ((typeof(callback) != "undefined") && (callback != null))
+				callback (doc, ctx);
 		}
-	} catch (e) {
-		if (errorCallback != null)
-			errorCallback (httpPost.responseText, ctx);
-		return;
 	}
-	callback (httpPost.responseText, ctx);
 }
 
 function WebForm_getFormData (theForm)