Author: lluis
Date: 2005-03-11 08:24:44 -0500 (Fri, 11 Mar 2005)
New Revision: 41696
Modified:
trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
trunk/mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs
trunk/mcs/class/System.Web/System.Web.UI/Control.cs
trunk/mcs/class/System.Web/System.Web.UI/Page.cs
trunk/mcs/class/System.Web/System.Web.UI/PostBackOptions.cs
trunk/mcs/class/System.Web/System.Web.UI/Utils.cs
Log:
2005-03-11 Lluis Sanchez Gual <[EMAIL PROTECTED]>
* Utils.cs, Control.cs: Don't use Page.GetPostBackClientEvent
since it is deprecated in 2.0.
* Page.cs: Deprecated GetPostBackClientEvent and similar methods
in 2.0. Moved callback management methods to ClientScriptManager.
* ClientScriptManager.cs: Moved here deprecated methods from Page.
In GetPostBackEventReference (PostBackOptions), don't use the
WebForm_DoPostback script if the post can be done with a simple
__doPostBack call.
* PostBackOptions.cs: Fixed default values for some properties.
Modified: trunk/mcs/class/System.Web/System.Web.UI/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/ChangeLog 2005-03-11 13:23:59 UTC
(rev 41695)
+++ trunk/mcs/class/System.Web/System.Web.UI/ChangeLog 2005-03-11 13:24:44 UTC
(rev 41696)
@@ -1,3 +1,15 @@
+2005-03-11 Lluis Sanchez Gual <[EMAIL PROTECTED]>
+
+ * Utils.cs, Control.cs: Don't use Page.GetPostBackClientEvent
+ since it is deprecated in 2.0.
+ * Page.cs: Deprecated GetPostBackClientEvent and similar methods
+ in 2.0. Moved callback management methods to ClientScriptManager.
+ * ClientScriptManager.cs: Moved here deprecated methods from Page.
+ In GetPostBackEventReference (PostBackOptions), don't use the
+ WebForm_DoPostback script if the post can be done with a simple
+ __doPostBack call.
+ * PostBackOptions.cs: Fixed default values for some properties.
+
2005-03-09 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* Control.cs: in FindControl, throw if there's more than one control
Modified: trunk/mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs
2005-03-11 13:23:59 UTC (rev 41695)
+++ trunk/mcs/class/System.Web/System.Web.UI/ClientScriptManager.cs
2005-03-11 13:24:44 UTC (rev 41696)
@@ -50,11 +50,95 @@
Hashtable hiddenFields;
internal Hashtable submitStatements;
Hashtable scriptIncludes;
+ Page page;
- internal ClientScriptManager ()
+ internal ClientScriptManager (Page page)
{
+ this.page = page;
}
+ public string GetPostBackClientEvent (Control control, string
argument)
+ {
+ return GetPostBackEventReference (control, argument);
+ }
+
+ public string GetPostBackClientHyperlink (Control control,
string argument)
+ {
+ return "javascript:" + GetPostBackEventReference
(control, argument);
+ }
+
+ public string GetPostBackEventReference (Control control)
+ {
+ return GetPostBackEventReference (control, "");
+ }
+
+ public string GetPostBackEventReference (Control control,
string argument)
+ {
+ page.RequiresPostBackScript ();
+ return String.Format ("__doPostBack('{0}','{1}')",
control.UniqueID, argument);
+ }
+
+#if NET_2_0
+ public string GetPostBackEventReference (PostBackOptions
options)
+ {
+ if (options.ActionUrl == null &&
options.ValidationGroup == null && !options.TrackFocus &&
+ !options.AutoPostBack &&
!options.PerformValidation)
+ {
+ if (options.RequiresJavaScriptProtocol)
+ return GetPostBackClientHyperlink
(options.TargetControl, options.Argument);
+ else
+ return GetPostBackEventReference
(options.TargetControl, options.Argument);
+ }
+
+ if (!IsClientScriptIncludeRegistered (typeof(Page),
"webform")) {
+ RegisterClientScriptInclude (typeof(Page),
"webform", GetWebResourceUrl (typeof(Page), "webform.js"));
+ }
+
+ if (options.ActionUrl != null)
+ RegisterHiddenField (page.PreviousPageID,
page.Request.FilePath);
+
+ if (options.ClientSubmit || options.ActionUrl != null)
+ page.RequiresPostBackScript ();
+
+ return String.Format
("{0}WebForm_DoPostback({1},{2},{3},{4},{5},{6},{7},{8})",
+ options.RequiresJavaScriptProtocol ?
"javascript:" : "",
+ ClientScriptManager.GetScriptLiteral
(options.TargetControl.UniqueID),
+ ClientScriptManager.GetScriptLiteral
(options.Argument),
+ ClientScriptManager.GetScriptLiteral
(options.ActionUrl),
+ ClientScriptManager.GetScriptLiteral
(options.AutoPostBack),
+ ClientScriptManager.GetScriptLiteral
(options.PerformValidation),
+ ClientScriptManager.GetScriptLiteral
(options.TrackFocus),
+ ClientScriptManager.GetScriptLiteral
(options.ClientSubmit),
+ ClientScriptManager.GetScriptLiteral
(options.ValidationGroup)
+ );
+ }
+
+ public string GetCallbackEventReference (Control control,
string argument, string clientCallback, string context)
+ {
+ return GetCallbackEventReference (control, argument,
clientCallback, context, null);
+ }
+
+ public string GetCallbackEventReference (Control control,
string argument, string clientCallback, string context, string
clientErrorCallback)
+ {
+ if (!IsClientScriptIncludeRegistered (typeof(Page),
"callback"))
+ RegisterClientScriptInclude (typeof(Page),
"callback", GetWebResourceUrl (typeof(Page), "callback.js"));
+
+ return string.Format ("WebForm_DoCallback ('{0}', {1},
{2}, {3}, {4})", control.UniqueID, argument, clientCallback, context,
clientErrorCallback);
+ }
+
+ public string GetWebResourceUrl(Type type, string resourceName)
+ {
+ if (type == null)
+ throw new ArgumentNullException ("type");
+
+ if (resourceName == null || resourceName.Length == 0)
+ throw new ArgumentNullException ("type");
+
+ return
System.Web.Handlers.AssemblyResourceLoader.GetResourceUrl (type, resourceName);
+ }
+
+#endif
+
public bool IsClientScriptBlockRegistered (string key)
{
return IsScriptRegistered (clientScriptBlocks,
GetType(), key);
@@ -271,7 +355,9 @@
internal static string GetScriptLiteral (object ob)
{
- if (ob is string) {
+ if (ob == null)
+ return "null";
+ else if (ob is string) {
string s = (string)ob;
s = s.Replace ("\"", "\\\"");
return "\"" + s + "\"";
Modified: trunk/mcs/class/System.Web/System.Web.UI/Control.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/Control.cs 2005-03-11 13:23:59 UTC
(rev 41695)
+++ trunk/mcs/class/System.Web/System.Web.UI/Control.cs 2005-03-11 13:24:44 UTC
(rev 41696)
@@ -1041,7 +1041,7 @@
#if NET_2_0
protected string GetWebResourceUrl (string resourceName)
{
- return Page.GetWebResourceUrl (GetType(),
resourceName);
+ return Page.ClientScript.GetWebResourceUrl (GetType(),
resourceName);
}
string IUrlResolutionService.ResolveClientUrl (string url)
Modified: trunk/mcs/class/System.Web/System.Web.UI/Page.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/Page.cs 2005-03-11 13:23:59 UTC
(rev 41695)
+++ trunk/mcs/class/System.Web/System.Web.UI/Page.cs 2005-03-11 13:24:44 UTC
(rev 41696)
@@ -82,7 +82,7 @@
string viewStateUserKey;
NameValueCollection _requestValueCollection;
string clientTarget;
- ClientScriptManager scriptManager = new ClientScriptManager ();
+ ClientScriptManager scriptManager;
[EditorBrowsable (EditorBrowsableState.Never)]
protected const string postEventArgumentID = "__EVENTARGUMENT";
@@ -90,9 +90,9 @@
protected const string postEventSourceID = "__EVENTTARGET";
#if NET_2_0
- private const string callbackArgumentID = "__CALLBACKARGUMENT";
- private const string callbackSourceID = "__CALLBACKTARGET";
- private const string previousPageID = "__PREVIOUSPAGE";
+ internal const string CallbackArgumentID = "__CALLBACKARGUMENT";
+ internal const string CallbackSourceID = "__CALLBACKTARGET";
+ internal const string PreviousPageID = "__PREVIOUSPAGE";
IPageHeader htmlHeader;
@@ -109,6 +109,7 @@
#region Constructor
public Page ()
{
+ scriptManager = new ClientScriptManager (this);
Page = this;
}
@@ -535,30 +536,41 @@
return coll;
}
-
+
+#if NET_2_0
+ [Obsolete]
+#endif
[EditorBrowsable (EditorBrowsableState.Advanced)]
public string GetPostBackClientEvent (Control control, string argument)
{
- return GetPostBackEventReference (control, argument);
+ return scriptManager.GetPostBackClientEvent (control, argument);
}
+#if NET_2_0
+ [Obsolete]
+#endif
[EditorBrowsable (EditorBrowsableState.Advanced)]
public string GetPostBackClientHyperlink (Control control, string
argument)
{
- return "javascript:" + GetPostBackEventReference (control,
argument);
+ return scriptManager.GetPostBackClientHyperlink (control,
argument);
}
+#if NET_2_0
+ [Obsolete]
+#endif
[EditorBrowsable (EditorBrowsableState.Advanced)]
public string GetPostBackEventReference (Control control)
{
- return GetPostBackEventReference (control, "");
+ return scriptManager.GetPostBackEventReference (control);
}
+#if NET_2_0
+ [Obsolete]
+#endif
[EditorBrowsable (EditorBrowsableState.Advanced)]
public string GetPostBackEventReference (Control control, string
argument)
{
- RequiresPostBackScript ();
- return String.Format ("__doPostBack('{0}','{1}')",
control.UniqueID, argument);
+ return scriptManager.GetPostBackEventReference (control,
argument);
}
internal void RequiresPostBackScript ()
@@ -1265,17 +1277,6 @@
_form = form;
}
- public string GetWebResourceUrl(Type type, string resourceName)
- {
- if (type == null)
- throw new ArgumentNullException ("type");
-
- if (resourceName == null || resourceName.Length == 0)
- throw new ArgumentNullException ("type");
-
- return
System.Web.Handlers.AssemblyResourceLoader.GetResourceUrl (type, resourceName);
- }
-
Stack dataItemCtx;
internal void PushDataItemContext (object o)
@@ -1328,47 +1329,6 @@
return XPathBinder.Select (CurrentDataItem, xpathexpression);
}
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public string GetCallbackEventReference (Control control, string
argument, string clientCallback, string context)
- {
- return GetCallbackEventReference (control, argument,
clientCallback, context, null);
- }
-
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public string GetCallbackEventReference (Control control, string
argument, string clientCallback, string context, string clientErrorCallback)
- {
- if (!ClientScript.IsClientScriptIncludeRegistered
(typeof(Page), "callback"))
- ClientScript.RegisterClientScriptInclude (typeof(Page),
"callback", GetWebResourceUrl (typeof(Page), "callback.js"));
-
- return string.Format ("WebForm_DoCallback ('{0}', {1}, {2},
{3}, {4})", control.UniqueID, argument, clientCallback, context,
clientErrorCallback);
- }
-
- [EditorBrowsable (EditorBrowsableState.Advanced)]
- public string GetPostBackEventReference (PostBackOptions options)
- {
- if (!ClientScript.IsClientScriptIncludeRegistered
(typeof(Page), "webform")) {
- ClientScript.RegisterClientScriptInclude (typeof(Page),
"webform", GetWebResourceUrl (typeof(Page), "webform.js"));
- }
-
- if (options.ActionUrl != null)
- ClientScript.RegisterHiddenField (previousPageID,
_context.Request.FilePath);
-
- if (options.ClientSubmit || options.ActionUrl != null)
- RequiresPostBackScript ();
-
- return String.Format
("{0}WebForm_DoPostback({1},{2},{3},{4},{5},{6},{7},{8})",
- options.RequiresJavaScriptProtocol ?
"javascript:" : "",
- ClientScriptManager.GetScriptLiteral
(options.TargetControl.UniqueID),
- ClientScriptManager.GetScriptLiteral
(options.Argument),
- ClientScriptManager.GetScriptLiteral
(options.ActionUrl),
- ClientScriptManager.GetScriptLiteral
(options.AutoPostBack),
- ClientScriptManager.GetScriptLiteral
(options.PerformValidation),
- ClientScriptManager.GetScriptLiteral
(options.TrackFocus),
- ClientScriptManager.GetScriptLiteral
(options.ClientSubmit),
- ClientScriptManager.GetScriptLiteral
(options.ValidationGroup)
- );
- }
-
[BrowsableAttribute (false)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public Page PreviousPage {
@@ -1379,7 +1339,7 @@
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[BrowsableAttribute (false)]
public bool IsCallback {
- get { return _requestValueCollection != null &&
_requestValueCollection [callbackArgumentID] != null; }
+ get { return _requestValueCollection != null &&
_requestValueCollection [CallbackArgumentID] != null; }
}
[BrowsableAttribute (false)]
@@ -1390,7 +1350,7 @@
string ProcessCallbackData ()
{
- string callbackTarget = _requestValueCollection
[callbackSourceID];
+ string callbackTarget = _requestValueCollection
[CallbackSourceID];
if (callbackTarget == null || callbackTarget.Length == 0)
throw new HttpException ("Callback target not
provided.");
@@ -1398,7 +1358,7 @@
if (target == null)
throw new HttpException (string.Format ("Invalid
callback target '{0}'.", callbackTarget));
- string callbackArgument = _requestValueCollection
[callbackArgumentID];
+ string callbackArgument = _requestValueCollection
[CallbackArgumentID];
return target.RaiseCallbackEvent (callbackArgument);
}
@@ -1505,7 +1465,7 @@
void LoadPreviousPageReference ()
{
if (_requestValueCollection != null) {
- string prevPage = _requestValueCollection
[previousPageID];
+ string prevPage = _requestValueCollection
[PreviousPageID];
if (prevPage != null) {
previousPage = (Page)
PageParser.GetCompiledPageInstance (prevPage, Server.MapPath (prevPage),
Context);
previousPage.ProcessCrossPagePostBack
(_context);
Modified: trunk/mcs/class/System.Web/System.Web.UI/PostBackOptions.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/PostBackOptions.cs 2005-03-11
13:23:59 UTC (rev 41695)
+++ trunk/mcs/class/System.Web/System.Web.UI/PostBackOptions.cs 2005-03-11
13:24:44 UTC (rev 41696)
@@ -44,13 +44,13 @@
private bool performValidation;
private string validationGroup;
- public PostBackOptions (Control control) : this (control,
string.Empty, string.Empty, false, false, false,
- false, false,
string.Empty)
+ public PostBackOptions (Control control) : this (control, null,
null, false, false, false,
+ false, false,
null)
{
}
- public PostBackOptions (Control control, string argument) :
this (control, argument, string.Empty, false,
-
false, false, false, false, string.Empty)
+ public PostBackOptions (Control control, string argument) :
this (control, argument, null, false,
+
false, false, false, false, null)
{
}
@@ -121,11 +121,11 @@
// client script.
internal bool RequiresSpecialPostBack {
get {
- return actionUrl != "" ||
- (validationGroup != "") ||
+ return actionUrl != null ||
+ validationGroup != null ||
trackFocus ||
autoPostBack ||
- argument != "";
+ argument != null;
}
}
}
Modified: trunk/mcs/class/System.Web/System.Web.UI/Utils.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/Utils.cs 2005-03-11 13:23:59 UTC
(rev 41695)
+++ trunk/mcs/class/System.Web/System.Web.UI/Utils.cs 2005-03-11 13:24:44 UTC
(rev 41696)
@@ -62,7 +62,7 @@
internal static string GetClientValidatedPostBack(Control
control)
{
return (" { if (typeof(Page_ClientValidate) !=
'function' || Page_ClientValidate()) " +
- control.Page.GetPostBackEventReference(control)
+
+
control.Page.ClientScript.GetPostBackEventReference(control) +
" } " );
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches