Esempio n. 1
0
        private void PreRenderSmartNavigation()
        {
            ISmartNavigablePage smartNavigablePage = _page as ISmartNavigablePage;

            if (smartNavigablePage == null)
            {
                return;
            }

            NameValueCollection postBackCollection = _page.GetPostBackCollection();

            if (smartNavigablePage.IsSmartScrollingEnabled)
            {
                string smartScrollingValue = null;
                if (postBackCollection != null && !_isSmartNavigationDataDisacarded)
                {
                    smartScrollingValue = postBackCollection[c_smartScrollingID];
                }
                _page.ClientScript.RegisterHiddenField(_page, c_smartScrollingID, smartScrollingValue);
            }

            if (smartNavigablePage.IsSmartFocusingEnabled)
            {
                string smartFocusValue = null;
                if (postBackCollection != null && !_isSmartNavigationDataDisacarded)
                {
                    smartFocusValue = postBackCollection[c_smartFocusID];
                }
                if (!string.IsNullOrEmpty(_smartFocusID))
                {
                    smartFocusValue = _smartFocusID;
                }
                _page.ClientScript.RegisterHiddenField(_page, c_smartFocusID, smartFocusValue);
            }
        }
            protected override void OnActiveViewChanged(EventArgs e)
            {
                base.OnActiveViewChanged(e);

                ISmartNavigablePage smartNavigablePage = Page as ISmartNavigablePage;

                if (smartNavigablePage != null)
                {
                    smartNavigablePage.DiscardSmartNavigationData();
                }
            }
Esempio n. 3
0
        /// <summary>
        ///   Implements <see cref="IWxePage.GetPermanentUrlParameters">IWxePage.GetPermanentUrlParameters()</see>.
        /// </summary>
        public NameValueCollection GetPermanentUrlParameters()
        {
            NameValueCollection urlParameters = CurrentPageFunction.VariablesContainer.SerializeParametersForQueryString();

            ISmartNavigablePage smartNavigablePage = _page as ISmartNavigablePage;

            if (smartNavigablePage != null)
            {
                NameValueCollectionUtility.Append(urlParameters, smartNavigablePage.GetNavigationUrlParameters());
            }

            return(urlParameters);
        }
Esempio n. 4
0
        /// <summary> Creates a <see cref="CommandInfo"/> for the <see cref="HrefCommand"/>. </summary>
        /// <param name="parameters">
        ///   The strings inserted into the href attribute using <c>string.Format</c>.
        /// </param>
        /// <param name="onClick">
        ///   The string always rendered in the <c>onClick</c> tag of the anchor element.
        /// </param>
        /// <param name="additionalUrlParameters">
        ///   The <see cref="NameValueCollection"/> containing additional url parameters.
        ///   Must not be <see langword="null"/>.
        /// </param>
        /// <param name="includeNavigationUrlParameters">
        ///   <see langword="true"/> to include URL parameters provided by <see cref="ISmartNavigablePage"/>.
        ///   Defaults to <see langword="true"/>.
        /// </param>
        /// <exception cref="InvalidOperationException">
        ///   If called while the <see cref="Type"/> is not set to <see cref="CommandType.Href"/>.
        /// </exception>
        protected virtual CommandInfo GetCommandInfoForHrefCommand(
            string[] parameters,
            string onClick,
            NameValueCollection additionalUrlParameters,
            bool includeNavigationUrlParameters)
        {
            ArgumentUtility.CheckNotNull("parameters", parameters);
            ArgumentUtility.CheckNotNull("additionalUrlParameters", additionalUrlParameters);
            if (Type != CommandType.Href)
            {
                throw new InvalidOperationException("Call to GetCommandInfoForHrefCommand not allowed unless Type is set to CommandType.Href.");
            }

            string href = HrefCommand.FormatHref(parameters);

            if (includeNavigationUrlParameters)
            {
                ISmartNavigablePage page = null;
                if (OwnerControl != null)
                {
                    page = OwnerControl.Page as ISmartNavigablePage;
                }

                if (page != null)
                {
                    additionalUrlParameters = additionalUrlParameters.Clone();
                    NameValueCollectionUtility.Append(additionalUrlParameters, page.GetNavigationUrlParameters());
                }
            }
            href = UrlUtility.AddParameters(href, additionalUrlParameters);
            if (OwnerControl != null)
            {
                href = OwnerControl.ResolveClientUrl(href);
            }

            return(CommandInfo.CreateForLink(
                       StringUtility.EmptyToNull(_toolTip),
                       StringUtility.EmptyToNull(_accessKey),
                       href,
                       StringUtility.EmptyToNull(HrefCommand.Target),
                       StringUtility.EmptyToNull(onClick)));
        }
Esempio n. 5
0
        private void RegisterSmartPageInitializationScript()
        {
            var htmlForm = _page.Form;

            if (htmlForm == null)
            {
                throw new InvalidOperationException("SmartPage requires an HtmlForm control on the page.");
            }

            string abortMessage = GetAbortMessage();
            string statusIsSubmittingMessage = GetStatusIsSubmittingMessage();

            string checkFormStateFunction = "null";

            if (!string.IsNullOrEmpty(_checkFormStateFunction))
            {
                checkFormStateFunction = "'" + _checkFormStateFunction + "'";
            }

            string smartScrollingFieldID = "null";
            string smartFocusFieldID     = "null";

            ISmartNavigablePage smartNavigablePage = _page as ISmartNavigablePage;

            if (smartNavigablePage != null)
            {
                if (smartNavigablePage.IsSmartScrollingEnabled)
                {
                    smartScrollingFieldID = "'" + c_smartScrollingID + "'";
                }
                if (smartNavigablePage.IsSmartFocusingEnabled)
                {
                    smartFocusFieldID = "'" + c_smartFocusID + "'";
                }
            }

            string isDirtyStateTrackingEnabled = "false";
            string isDirty = "false";

            StringBuilder initScript = new StringBuilder(500);

            initScript.AppendLine("function SmartPage_Initialize ()");
            initScript.AppendLine("{");

            const string eventHandlersArray = "eventHandlers";

            initScript.Append("  var ").Append(eventHandlersArray).AppendLine(" = new Array();");
            FormatPopulateEventHandlersArrayClientScript(initScript, eventHandlersArray);
            initScript.AppendLine();

            const string trackedControlsArray = "trackedControls";

            initScript.Append("  var ").Append(trackedControlsArray).AppendLine(" = new Array();");
            if (_page.IsDirtyStateTrackingEnabled)
            {
                isDirtyStateTrackingEnabled = "true";
                if (_page.EvaluateDirtyState())
                {
                    isDirty = "true";
                }
                else
                {
                    FormatPopulateTrackedControlsArrayClientScript(initScript, trackedControlsArray);
                }
            }
            initScript.AppendLine();

            const string synchronousPostBackCommandsArray = "synchronousPostBackCommands";

            initScript.Append("  var ").Append(synchronousPostBackCommandsArray).AppendLine(" = new Array();");
            FormatPopulateSynchronousPostBackCommandsArrayClientScript(initScript, synchronousPostBackCommandsArray);
            initScript.AppendLine();

            initScript.AppendLine("  if (SmartPage_Context.Instance == null)");
            initScript.AppendLine("  {");

            initScript.AppendLine();

            initScript.AppendLine("    SmartPage_Context.Instance = new SmartPage_Context (");
            initScript.Append("        '").Append(htmlForm.ClientID).AppendLine("',");
            initScript.Append("        ").Append(isDirtyStateTrackingEnabled).AppendLine(",");
            initScript.Append("        ").Append(abortMessage).AppendLine(",");
            initScript.Append("        ").Append(statusIsSubmittingMessage).AppendLine(",");
            initScript.Append("        ").Append(smartScrollingFieldID).AppendLine(",");
            initScript.Append("        ").Append(smartFocusFieldID).AppendLine(",");
            initScript.Append("        ").Append(checkFormStateFunction).AppendLine(");");

            initScript.AppendLine("  }");
            initScript.AppendLine();

            initScript.Append("  SmartPage_Context.Instance.set_EventHandlers (").Append(eventHandlersArray).AppendLine(");");
            initScript.Append("  SmartPage_Context.Instance.set_TrackedIDs (").Append(trackedControlsArray).AppendLine(");");
            initScript.Append("  SmartPage_Context.Instance.set_SynchronousPostBackCommands (").Append(synchronousPostBackCommandsArray).AppendLine(");");
            initScript.AppendLine("}");
            initScript.AppendLine();
            initScript.AppendLine("SmartPage_Initialize ();");
            initScript.AppendLine();

            _page.ClientScript.RegisterClientScriptBlock(_page, typeof(SmartPageInfo), "smartPageInitialize", initScript.ToString());

            string isAsynchronous = "false";

            if (IsInAsyncPostBack)
            {
                isAsynchronous = "true";
            }
            _page.ClientScript.RegisterStartupScriptBlock(_page, typeof(SmartPageInfo), "smartPageStartUp", "SmartPage_OnStartUp (" + isAsynchronous + ", " + isDirty + ");");

            // Ensure the __doPostBack function and the __EventTarget and __EventArgument hidden fields on the rendered page
            _page.ClientScript.GetPostBackEventReference(new PostBackOptions(_page.WrappedInstance)
            {
                ClientSubmit = true
            }, false);
        }