protected internal override void Render(HtmlTextWriter markupWriter)
        {
            WmlTextWriter writer = (WmlTextWriter)markupWriter;

            // If control is not enabled, don't render it at
            // all for WML.
            if (!Control.Enabled)
            {
                RenderDisabled(writer);
                return;
            }

            ((WmlPageAdapter)PageAdapter).RegisterPostField(writer, Control);

            // determine if control is already checked.
            // if so, set initial value.
            _ivalue = Control.Checked ? "1" : String.Empty;

            ((WmlPageAdapter)PageAdapter).AddFormVariable(writer, Control.ClientID, _ivalue, false /* randomID */);
            // does not render __ivalue if null or form variables written.
            writer.WriteBeginSelect(null, null, Control.ClientID, _ivalue, Control.ToolTip, true /* multiselect*/);

            if (Control.AutoPostBack)
            {
                ((WmlPageAdapter)PageAdapter).RenderSelectOptionAsAutoPostBack(writer, Control.Text, null);
            }
            else
            {
                ((WmlPageAdapter)PageAdapter).RenderSelectOption(writer, Control.Text);
            }

            writer.WriteEndSelect();
        }
Esempio n. 2
0
        protected internal override void Render(HtmlTextWriter markupWriter)
        {
            WmlTextWriter writer = (WmlTextWriter)markupWriter;

            ListItemCollection items = Control.Items;
            int count = items.Count;

            if (count == 0)
            {
                return;
            }

            writer.EnterStyle(Control.ControlStyle);
            bool selected = false;

            if (!Control.Enabled)
            {
                foreach (ListItem item in items)
                {
                    // VSWhidbey 115824
                    if (item.Selected)
                    {
                        if (selected)
                        {
                            Control.VerifyMultiSelect();
                        }
                        selected = true;
                    }
                    RenderDisabledItem(writer, item);
                }
            }
            else
            {
                // Only register post fields if the control is enabled.
                ((WmlPageAdapter)PageAdapter).RegisterPostField(writer, Control);

                if (_ivalue != null)
                {
                    ((WmlPageAdapter)PageAdapter).AddFormVariable(writer, Control.ClientID, _ivalue, false);
                }
                // does not render _ivalue if null or form variables written.
                writer.WriteBeginSelect(null /*name*/,
                                        null /*value*/,
                                        Control.ClientID /*iname*/,
                                        _ivalue /*ivalue*/,
                                        Control.ToolTip /*title*/,
                                        IsMultiSelect);

                foreach (ListItem item in items)
                {
                    // If the item is disabled, don't render it.
                    // WML only allows selectable <options> within <select> elements.
                    if (!item.Enabled)
                    {
                        continue;
                    }

                    // VSWhidbey 115824
                    if (item.Selected)
                    {
                        if (selected && !IsMultiSelect)
                        {
                            throw new HttpException(SR.GetString(SR.Cant_Multiselect_In_Single_Mode));
                        }
                        selected = true;
                    }
                    RenderSelectOption(writer, item);
                }
                writer.WriteEndSelect();
            }

            writer.ExitStyle(Control.ControlStyle);
        }
        // Renders the control.
        protected internal override void Render(HtmlTextWriter markupWriter)
        {
            WmlTextWriter writer = (WmlTextWriter)markupWriter;

            DetermineGroup(Control);
            RadioButtonGroup group = GetGroupByName(Control.UniqueGroupName);

            if (group != null)
            {
                if (!group.RegisteredGroup)
                {
                    // GroupFormVariable is passed as the name & value becuase it is both the key
                    // for the postback data, and the WML client side var used to
                    // select an item in the list.
                    ((WmlPageAdapter)PageAdapter).RegisterPostField(writer, GroupFormVariable, GroupFormVariable, true /*dynamic field*/, false /*random*/);
                    group.RegisteredGroup = true;
                }
                if (group.RenderAsGroup)
                {
                    // Render opening select if not already opened
                    if (!group.RenderedSelect)
                    {
                        if (group.SelectedButton != null)
                        {
                            ((WmlPageAdapter)PageAdapter).AddFormVariable(writer, GroupFormVariable, group.SelectedButton, false /*random*/);
                        }
                        writer.WriteBeginSelect(GroupFormVariable, group.SelectedButton, null /*iname */,
                                                null /*ivalue*/, Control.ToolTip, false /*multiple */);
                        if (!writer.AnalyzeMode)
                        {
                            group.RenderedSelect = true;
                        }
                    }

                    // Render option
                    // We don't do autopostback if the radio button has been selected.
                    // This is to make it consistent that it only posts back if its
                    // state has been changed.  Also, it avoids the problem of missing
                    // validation since the data changed event would not be fired if the
                    // selected radio button was posting back.
                    if (Control.AutoPostBack && !Control.Checked)
                    {
                        ((WmlPageAdapter)PageAdapter).RenderSelectOptionAsAutoPostBack(writer, Control.Text, Control.UniqueID);
                    }
                    else
                    {
                        ((WmlPageAdapter)PageAdapter).RenderSelectOption(writer, Control.Text, Control.UniqueID);
                    }

                    // Close, if list is finished
                    if (!writer.AnalyzeMode && --group.ButtonsInGroup == 0)
                    {
                        writer.WriteEndSelect();
                    }
                }
                // must render as autopostback, radio buttons not in consecutive group.
                else
                {
                    if (!Control.Enabled)
                    {
                        RenderDisabled(writer);
                        return;
                    }

                    string iname  = Control.Checked ? Control.ClientID : null;
                    string ivalue = Control.Checked ? "1" : null;
                    if (ivalue != null)
                    {
                        ((WmlPageAdapter)PageAdapter).AddFormVariable(writer, iname, ivalue, false /*random*/);
                    }

                    writer.WriteBeginSelect(null, null, iname, ivalue, Control.ToolTip, true /*multiple*/);
                    if (!Control.Checked)
                    {
                        ((WmlPageAdapter)PageAdapter).RenderSelectOptionAsAutoPostBack(writer, Control.Text, GroupFormVariable, Control.UniqueID);
                    }
                    else
                    {
                        ((WmlPageAdapter)PageAdapter).RenderSelectOption(writer, Control.Text, Control.UniqueID);
                    }
                    writer.WriteEndSelect();
                }
            }
        }