private void RenderOpeningBodyElement(XhtmlMobileTextWriter writer)
        {
            Form  activeForm = Page.ActiveForm;
            Style formStyle  = ((ControlAdapter)activeForm.Adapter).Style;

            if (CssLocation == StyleSheetLocation.PhysicalFile)
            {
                String cssClass = (String)activeForm.CustomAttributes[XhtmlConstants.CssClassCustomAttribute];
                writer.WriteBeginTag("body");
                if (cssClass != null && (String)Device["supportsBodyClassAttribute"] != "false")
                {
                    writer.WriteAttribute("class", cssClass, true /* encode */);
                    writer.PushPhysicalCssClass(cssClass);
                    _pushedCssClassForBody = true;
                }
                writer.Write(">");
            }
            else if ((String)Device[XhtmlConstants.RequiresXhtmlCssSuppression] != "true" &&
                     (String)Device[XhtmlConstants.SupportsBodyClassAttribute] != "false")
            {
                writer.EnterStyle(formStyle, "body");
            }
            else
            {
                writer.WriteFullBeginTag("body");
                if ((String)Device[XhtmlConstants.RequiresXhtmlCssSuppression] != "true" &&
                    (String)Device[XhtmlConstants.SupportsBodyClassAttribute] == "false")
                {
                    writer.SetBodyStyle(formStyle);
                }
            }
        }
        /////////////////////////////////////////////////////////////////////////
        // SPECIALIZED UTILITY METHODS FOR LIST SELECTIONLIST OBJECTLIST
        /////////////////////////////////////////////////////////////////////////

        // tagname can be any of table, ul, ol.  See the list adapters for examples.
        /// <include file='doc\XhtmlBasicControlAdapter.uex' path='docs/doc[@for="XhtmlControlAdapter.RenderOpeningListTag"]/*' />
        protected virtual void RenderOpeningListTag(XhtmlMobileTextWriter writer, String tagName)
        {
            String classAttribute = (String)Control.CustomAttributes[XhtmlConstants.CssClassCustomAttribute];

            if (CssLocation == StyleSheetLocation.PhysicalFile && (String)Device[XhtmlConstants.RequiresXhtmlCssSuppression] != "true")
            {
                writer.WritePendingBreak();
                writer.WriteBeginTag(tagName);
                if (classAttribute != null &&
                    classAttribute.Length > 0 &&
                    writer.DiffersFromCurrentPhysicalCssClass(classAttribute))
                {
                    writer.WriteAttribute("class", classAttribute, true);
                    writer.PushPhysicalCssClass(classAttribute);
                    Debug.Assert(!_physicalCssClassPushed, "These calls should not be nested.");
                    _physicalCssClassPushed = true;
                }
                writer.Write(">");
            }
            else if ((String)Device[XhtmlConstants.RequiresXhtmlCssSuppression] != "true")
            {
                writer.WritePendingBreak();
                StyleFilter filter = writer.CurrentStyleClass.GetFilter(Style);
                writer.EnterStyle(new XhtmlFormatStyleClass(Style, filter), tagName);
            }
            else
            {
                writer.WritePendingBreak();
                writer.WriteFullBeginTag(tagName);
            }
        }
        /////////////////////////////////////////////////////////////////////////
        // SPECIALIZED UTILITY METHODS FOR LIST SELECTIONLIST OBJECTLIST
        /////////////////////////////////////////////////////////////////////////

        // tagname can be any of table, ul, ol.  See the list adapters for examples.
        /// <include file='doc\XhtmlBasicControlAdapter.uex' path='docs/doc[@for="XhtmlControlAdapter.RenderOpeningListTag"]/*' />
        protected virtual void RenderOpeningListTag(XhtmlMobileTextWriter writer, String tagName) {            
            String classAttribute = (String) Control.CustomAttributes[XhtmlConstants.CssClassCustomAttribute];
            if (CssLocation == StyleSheetLocation.PhysicalFile && (String)Device[XhtmlConstants.RequiresXhtmlCssSuppression] != "true") {
                writer.WritePendingBreak();
                writer.WriteBeginTag(tagName);            
                if (classAttribute != null && 
                    classAttribute.Length > 0 &&
                    writer.DiffersFromCurrentPhysicalCssClass(classAttribute)) {
                    writer.WriteAttribute("class", classAttribute, true);
                    writer.PushPhysicalCssClass(classAttribute);
                    Debug.Assert(!_physicalCssClassPushed, "These calls should not be nested.");
                    _physicalCssClassPushed = true;
                }
                writer.Write(">");
            }
            else if ((String)Device[XhtmlConstants.RequiresXhtmlCssSuppression] != "true") {
                writer.WritePendingBreak();
                StyleFilter filter = writer.CurrentStyleClass.GetFilter(Style);
                writer.EnterStyle(new XhtmlFormatStyleClass(Style, filter), tagName);
            }
            else {
                writer.WritePendingBreak();
                writer.WriteFullBeginTag(tagName);
            }
        }
        /// <include file='doc\XhtmlBasicFormAdapter.uex' path='docs/doc[@for="XhtmlFormAdapter.Render"]/*' />
        public override void Render (XhtmlMobileTextWriter writer) {
            // Note: <head>, <body> rendered by page adapter, as in HTML case.
            String formsAuthCookieName = FormsAuthentication.FormsCookieName;
            if(!Device.SupportsRedirectWithCookie)
            {
                if(formsAuthCookieName != null && formsAuthCookieName.Length > 0)
                {
                    HttpContext.Current.Response.Cookies.Remove(formsAuthCookieName);
                }
            }
            writer.WriteBeginTag ("form");
            writer.WriteAttribute ("id", Control.ClientID);
            writer.WriteAttribute ("method", Control.Method.ToString().ToLower(CultureInfo.CurrentCulture));
            writer.Write (" action=\"");
            RenderPostbackUrl(writer);
            if(Control.Action.Length > 0) {
                if(Control.Action.IndexOf("?", StringComparison.Ordinal) != -1) {
                    writer.Write("&");
                }
                else {
                    writer.Write("?");
                }
            }
            else {
                writer.Write("?");
            }
            writer.Write(Page.UniqueFilePathSuffix);

            if (Control.Method != FormMethod.Get &&
                Control.Action.Length == 0) {   // VSWhidbey 411176: We don't include QueryStringText if Action is explicitly set

                String queryStringText = PreprocessQueryString(Page.QueryStringText);
                if (queryStringText != null && queryStringText.Length > 0) {
                    String amp = (String)Device[XhtmlConstants.SupportsUrlAttributeEncoding] != "false"  ? "&amp;" : "&";
                    writer.Write(amp);
                    if((String)Device[XhtmlConstants.SupportsUrlAttributeEncoding] != "false") {
                        writer.WriteEncodedText(queryStringText);
                    }
                    else {
                        writer.Write(queryStringText);
                    }
                }
            }
            writer.WriteLine ("\">");
            bool needDivStyle = (String)Device[XhtmlConstants.RequiresXhtmlCssSuppression] != "true" &&
                (String)Device["supportsBodyClassAttribute"] == "false";
            if (!needDivStyle) {
                if((String)Device["usePOverDiv"] == "true")
                    writer.WriteFullBeginTag("p");
                else
                    writer.WriteFullBeginTag ("div");
            }
            else {
                if((String)Device["usePOverDiv"] == "true")
                    writer.EnterStyle(Style, "p");
                else
                    writer.EnterStyle (Style, "div");
            }
            RenderPostBackHeader (writer);
            // Renders hidden variables for IPostBackDataHandlers which are
            // not displayed due to pagination or secondary UI.
            RenderOffPageVariables(writer, Control, Control.CurrentPage);
            
            RenderChildren (writer);
            if (!needDivStyle) {
                if((String)Device["usePOverDiv"] == "true")
                    writer.WriteEndTag("p");
                else
                    writer.WriteEndTag ("div");
            }
            else {
                if((String)Device["usePOverDiv"] == "true")
                    writer.ExitStyle(Style);
                else
                    writer.ExitStyle (Style);
            }
            writer.WriteEndTag ("form");
        }
 private void RenderOpeningBodyElement(XhtmlMobileTextWriter writer) {
     Form activeForm = Page.ActiveForm;
     Style formStyle = ((ControlAdapter)activeForm.Adapter).Style;
     if (CssLocation == StyleSheetLocation.PhysicalFile) {
         String cssClass = (String) activeForm.CustomAttributes[XhtmlConstants.CssClassCustomAttribute];
         writer.WriteBeginTag("body");
         if (cssClass != null  && (String)Device["supportsBodyClassAttribute"] != "false") {
             writer.WriteAttribute("class", cssClass, true /* encode */);
             writer.PushPhysicalCssClass(cssClass);
             _pushedCssClassForBody = true;
         }
         writer.Write(">");
     }
     else if ((String)Device[XhtmlConstants.RequiresXhtmlCssSuppression] != "true" &&
         (String)Device[XhtmlConstants.SupportsBodyClassAttribute] != "false") {
         writer.EnterStyle(formStyle, "body");
     }
     else {
         writer.WriteFullBeginTag("body");    
         if ((String)Device[XhtmlConstants.RequiresXhtmlCssSuppression] != "true" &&
             (String)Device[XhtmlConstants.SupportsBodyClassAttribute] == "false") {
             writer.SetBodyStyle(formStyle);
         }
     }
 }
        /// <include file='doc\XhtmlBasicPageAdapter.uex' path='docs/doc[@for="XhtmlPageAdapter.Render"]/*' />
        public override void Render (XhtmlMobileTextWriter writer) {
            writer.BeginResponse ();
            if (Page.Request.Browser["requiresPragmaNoCacheHeader"] == "true") {
                Page.Response.AppendHeader("Pragma", "no-cache");
            }
            InitWriterState(writer);          
            writer.BeginCachedRendering ();
            // For consistency with HTML, we render the form style with body tag.
            RenderOpeningBodyElement(writer);
            // Certain WML 2.0 devices require that we write an onevent onenterforward setvar snippet.
            // We cannot know the relevant variables until after the form is rendered, so we mark this
            // position.  The setvar elements will be inserted into the cached rendering here.
            writer.MarkWmlOnEventLocation ();
            Page.ActiveForm.RenderControl(writer);
            RenderClosingBodyElement(writer);
            writer.ClearPendingBreak ();
            writer.EndCachedRendering ();

            // Note: first and third arguments are not used.
            writer.BeginFile (Page.Request.Url.ToString (), Page.Device.PreferredRenderingMime, Page.Response.Charset);
            String supportsXmlDeclaration = Device["supportsXmlDeclaration"];
            // Invariant culture not needed, included for best practices compliance.
            if (supportsXmlDeclaration == null ||
                !String.Equals(supportsXmlDeclaration, "false", StringComparison.OrdinalIgnoreCase)) {
                writer.WriteXmlDeclaration ();
            }
            writer.WriteDoctypeDeclaration(DocumentType);
            // Review: Hard coded xmlns.
            writer.WriteFullBeginTag ("html xmlns=\"http://www.w3.org/1999/xhtml\"");
            writer.WriteLine ();
            writer.WriteFullBeginTag ("head");
            writer.WriteLine ();
            writer.WriteFullBeginTag ("title");
            if (Page.ActiveForm.Title != null) {
                writer.WriteEncodedText(Page.ActiveForm.Title);
            }
            writer.WriteEndTag ("title");
            ConditionalRenderLinkElement (writer);
            ConditionalRenderStyleElement (writer);
            writer.WriteEndTag ("head");
            writer.WriteLine ();
            writer.WriteCachedMarkup (); // includes body tag.
            writer.WriteLine ();
            writer.WriteEndTag ("html");
            writer.EndFile ();
            if (!DoesDeviceRequireCssSuppression()) {
                if (CssLocation == StyleSheetLocation.ApplicationCache && !writer.IsStyleSheetEmpty()) {
                    // Recall that Page.Cache has application scope
                    Page.Cache.Insert(writer.CacheKey, writer.GetStyles (), null, DateTime.MaxValue, _cacheExpirationTime);
                }
                else if (CssLocation == StyleSheetLocation.SessionState && !writer.IsStyleSheetEmpty()) {
                    Page.Session[writer.SessionKey] = writer.GetStyles();
                }
            }

            writer.EndResponse ();
        }
        /// <include file='doc\XhtmlBasicPageAdapter.uex' path='docs/doc[@for="XhtmlPageAdapter.Render"]/*' />
        public override void Render(XhtmlMobileTextWriter writer)
        {
            writer.BeginResponse();
            if (Page.Request.Browser["requiresPragmaNoCacheHeader"] == "true")
            {
                Page.Response.AppendHeader("Pragma", "no-cache");
            }
            InitWriterState(writer);
            writer.BeginCachedRendering();
            // For consistency with HTML, we render the form style with body tag.
            RenderOpeningBodyElement(writer);
            // Certain WML 2.0 devices require that we write an onevent onenterforward setvar snippet.
            // We cannot know the relevant variables until after the form is rendered, so we mark this
            // position.  The setvar elements will be inserted into the cached rendering here.
            writer.MarkWmlOnEventLocation();
            Page.ActiveForm.RenderControl(writer);
            RenderClosingBodyElement(writer);
            writer.ClearPendingBreak();
            writer.EndCachedRendering();

            // Note: first and third arguments are not used.
            writer.BeginFile(Page.Request.Url.ToString(), Page.Device.PreferredRenderingMime, Page.Response.Charset);
            String supportsXmlDeclaration = Device["supportsXmlDeclaration"];

            // Invariant culture not needed, included for best practices compliance.
            if (supportsXmlDeclaration == null ||
                !String.Equals(supportsXmlDeclaration, "false", StringComparison.OrdinalIgnoreCase))
            {
                writer.WriteXmlDeclaration();
            }
            writer.WriteDoctypeDeclaration(DocumentType);
            // Review: Hard coded xmlns.
            writer.WriteFullBeginTag("html xmlns=\"http://www.w3.org/1999/xhtml\"");
            writer.WriteLine();
            writer.WriteFullBeginTag("head");
            writer.WriteLine();
            writer.WriteFullBeginTag("title");
            if (Page.ActiveForm.Title != null)
            {
                writer.WriteEncodedText(Page.ActiveForm.Title);
            }
            writer.WriteEndTag("title");
            ConditionalRenderLinkElement(writer);
            ConditionalRenderStyleElement(writer);
            writer.WriteEndTag("head");
            writer.WriteLine();
            writer.WriteCachedMarkup();  // includes body tag.
            writer.WriteLine();
            writer.WriteEndTag("html");
            writer.EndFile();
            if (!DoesDeviceRequireCssSuppression())
            {
                if (CssLocation == StyleSheetLocation.ApplicationCache && !writer.IsStyleSheetEmpty())
                {
                    // Recall that Page.Cache has application scope
                    Page.Cache.Insert(writer.CacheKey, writer.GetStyles(), null, DateTime.MaxValue, _cacheExpirationTime);
                }
                else if (CssLocation == StyleSheetLocation.SessionState && !writer.IsStyleSheetEmpty())
                {
                    Page.Session[writer.SessionKey] = writer.GetStyles();
                }
            }

            writer.EndResponse();
        }
        /// <include file='doc\XhtmlBasicFormAdapter.uex' path='docs/doc[@for="XhtmlFormAdapter.Render"]/*' />
        public override void Render(XhtmlMobileTextWriter writer)
        {
            // Note: <head>, <body> rendered by page adapter, as in HTML case.
            String formsAuthCookieName = FormsAuthentication.FormsCookieName;

            if (!Device.SupportsRedirectWithCookie)
            {
                if (formsAuthCookieName != null && formsAuthCookieName.Length > 0)
                {
                    HttpContext.Current.Response.Cookies.Remove(formsAuthCookieName);
                }
            }
            writer.WriteBeginTag("form");
            writer.WriteAttribute("id", Control.ClientID);
            writer.WriteAttribute("method", Control.Method.ToString().ToLower(CultureInfo.CurrentCulture));
            writer.Write(" action=\"");
            RenderPostbackUrl(writer);
            if (Control.Action.Length > 0)
            {
                if (Control.Action.IndexOf("?", StringComparison.Ordinal) != -1)
                {
                    writer.Write("&");
                }
                else
                {
                    writer.Write("?");
                }
            }
            else
            {
                writer.Write("?");
            }
            writer.Write(Page.UniqueFilePathSuffix);

            if (Control.Method != FormMethod.Get &&
                Control.Action.Length == 0)     // VSWhidbey 411176: We don't include QueryStringText if Action is explicitly set

            {
                String queryStringText = PreprocessQueryString(Page.QueryStringText);
                if (queryStringText != null && queryStringText.Length > 0)
                {
                    String amp = (String)Device[XhtmlConstants.SupportsUrlAttributeEncoding] != "false"  ? "&amp;" : "&";
                    writer.Write(amp);
                    if ((String)Device[XhtmlConstants.SupportsUrlAttributeEncoding] != "false")
                    {
                        writer.WriteEncodedText(queryStringText);
                    }
                    else
                    {
                        writer.Write(queryStringText);
                    }
                }
            }
            writer.WriteLine("\">");
            bool needDivStyle = (String)Device[XhtmlConstants.RequiresXhtmlCssSuppression] != "true" &&
                                (String)Device["supportsBodyClassAttribute"] == "false";

            if (!needDivStyle)
            {
                if ((String)Device["usePOverDiv"] == "true")
                {
                    writer.WriteFullBeginTag("p");
                }
                else
                {
                    writer.WriteFullBeginTag("div");
                }
            }
            else
            {
                if ((String)Device["usePOverDiv"] == "true")
                {
                    writer.EnterStyle(Style, "p");
                }
                else
                {
                    writer.EnterStyle(Style, "div");
                }
            }
            RenderPostBackHeader(writer);
            // Renders hidden variables for IPostBackDataHandlers which are
            // not displayed due to pagination or secondary UI.
            RenderOffPageVariables(writer, Control, Control.CurrentPage);

            RenderChildren(writer);
            if (!needDivStyle)
            {
                if ((String)Device["usePOverDiv"] == "true")
                {
                    writer.WriteEndTag("p");
                }
                else
                {
                    writer.WriteEndTag("div");
                }
            }
            else
            {
                if ((String)Device["usePOverDiv"] == "true")
                {
                    writer.ExitStyle(Style);
                }
                else
                {
                    writer.ExitStyle(Style);
                }
            }
            writer.WriteEndTag("form");
        }
        void RenderInputElementSet (XhtmlMobileTextWriter writer) {
            string wrappingTag = Device.Tables ? "table" : 
                (((string)Device["usePOverDiv"]  == "true") ? "p" : "div");
            ListSelectType selectType = Control.SelectType;
            MobileListItemCollection items = Control.Items;
            // Review: We always render a table.  Should we optimize away the table tags when the alignment is left?
            String selectTypeString =
                (selectType == ListSelectType.Radio) ?
                "radio" :
                "checkbox";

            ClearPendingBreakIfDeviceBreaksOnBlockLevel(writer); // Since we are writing a block-level element in all cases.
            ConditionalEnterLayout(writer, Style);
            RenderOpeningListTag(writer, wrappingTag);
            for(int itemIndex = 0; itemIndex < items.Count; itemIndex++) {
                MobileListItem item = items[itemIndex];
                if (Device.Tables) {
                    writer.WriteFullBeginTag("tr");
                    writer.WriteFullBeginTag("td");
                }

                writer.WriteBeginTag("input");
                writer.WriteAttribute("type", selectTypeString);
                writer.WriteAttribute("name", Control.UniqueID);
                WriteItemValueAttribute(writer, itemIndex, item.Value);
                String accessKey = GetCustomAttributeValue(item, XhtmlConstants.AccessKeyCustomAttribute);
                if (accessKey != null && accessKey.Length > 0) {
                    writer.WriteAttribute("accesskey", accessKey, true);
                }
                // Assumption: Device.SupportsUncheck is always true for Xhtml devices.
                if (item.Selected && 
                    (Control.IsMultiSelect || itemIndex == Control.SelectedIndex)) {
                    writer.Write(" checked=\"checked\"/>");
                }
                else {
                    writer.Write("/>");
                }

                writer.WriteEncodedText(item.Text);
                if (Device.Tables) {
                    writer.WriteEndTag("td");
                }
                if((string)Device["usePOverDiv"]  == "true" || !Device.Tables) {
                    writer.Write("<br/>");
                }
                if (Device.Tables) {
                    writer.WriteEndTag("tr");
                }
            }
            RenderClosingListTag(writer, wrappingTag);
            ConditionalExitLayout(writer, Style);
        }
        void RenderInputElementSet(XhtmlMobileTextWriter writer)
        {
            string wrappingTag = Device.Tables ? "table" :
                                 (((string)Device["usePOverDiv"] == "true") ? "p" : "div");
            ListSelectType           selectType = Control.SelectType;
            MobileListItemCollection items      = Control.Items;
            // Review: We always render a table.  Should we optimize away the table tags when the alignment is left?
            String selectTypeString =
                (selectType == ListSelectType.Radio) ?
                "radio" :
                "checkbox";

            ClearPendingBreakIfDeviceBreaksOnBlockLevel(writer); // Since we are writing a block-level element in all cases.
            ConditionalEnterLayout(writer, Style);
            RenderOpeningListTag(writer, wrappingTag);
            for (int itemIndex = 0; itemIndex < items.Count; itemIndex++)
            {
                MobileListItem item = items[itemIndex];
                if (Device.Tables)
                {
                    writer.WriteFullBeginTag("tr");
                    writer.WriteFullBeginTag("td");
                }

                writer.WriteBeginTag("input");
                writer.WriteAttribute("type", selectTypeString);
                writer.WriteAttribute("name", Control.UniqueID);
                WriteItemValueAttribute(writer, itemIndex, item.Value);
                String accessKey = GetCustomAttributeValue(item, XhtmlConstants.AccessKeyCustomAttribute);
                if (accessKey != null && accessKey.Length > 0)
                {
                    writer.WriteAttribute("accesskey", accessKey, true);
                }
                // Assumption: Device.SupportsUncheck is always true for Xhtml devices.
                if (item.Selected &&
                    (Control.IsMultiSelect || itemIndex == Control.SelectedIndex))
                {
                    writer.Write(" checked=\"checked\"/>");
                }
                else
                {
                    writer.Write("/>");
                }

                writer.WriteEncodedText(item.Text);
                if (Device.Tables)
                {
                    writer.WriteEndTag("td");
                }
                if ((string)Device["usePOverDiv"] == "true" || !Device.Tables)
                {
                    writer.Write("<br/>");
                }
                if (Device.Tables)
                {
                    writer.WriteEndTag("tr");
                }
            }
            RenderClosingListTag(writer, wrappingTag);
            ConditionalExitLayout(writer, Style);
        }