Example #1
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            // For the onclick script to be executed in IE 6 when the users presses Enter inside the form
            // the button needs to be the default button. (In Firefox it doesn't.)

            if (_isDefaultButton)
            {
                HtmlForm parentForm = ControlUtils.GetParentForm(this, true);
                if (string.IsNullOrEmpty(parentForm.DefaultButton))
                {
                    parentForm.DefaultButton = UniqueID;
                }
                else
                {
                    if (parentForm.DefaultButton != UniqueID)
                    {
                        throw new ApplicationException(string.Format("Form '{0}' contains a {1} '{2}', but the default"
                                                                     + " button has been set to '{3}'. This would prevent the onclick JavaScript from running"
                                                                     + " when the user submits the form by pressing Enter in IE.",
                                                                     parentForm.ClientID, GetType().Name, UniqueID, parentForm.DefaultButton));
                    }
                }
            }
        }
Example #2
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (_isDefaultButton)
            {
                HtmlForm parentForm = ControlUtils.GetParentForm(this, true);
                if (parentForm.DefaultButton != UniqueID)
                {
                    throw new ApplicationException(string.Format("Form '{0}' contains a {1} '{2}', which is not set"
                                                                 + " as the default button (probably because another control overwrote the DefaultButton"
                                                                 + " property). This would prevent the onclick JavaScript from running when the user submits"
                                                                 + " the form by pressing Enter in IE.", parentForm.UniqueID, GetType().Name, UniqueID));
                }
            }
        }
Example #3
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // If this button is the Default button process postbacks without an event target, which
            // would happen if the client has JavaScript disabled.

            if (Page.IsPostBack)
            {
                HtmlForm parentForm = ControlUtils.GetParentForm(this, false);

                if (parentForm != null && !string.IsNullOrEmpty(parentForm.DefaultButton) &&
                    parentForm.DefaultButton == UniqueID && string.IsNullOrEmpty(Page.Request.Form[EVENT_TARGET_FIELD]))
                {
                    OnClick(EventArgs.Empty);
                }
            }
        }