• About Us
  • Blog
  • Basket
  • Account
  • Sign In
  •  

Forums

PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 23 Apr 2012 06:18 AM by  Murali Setty
(SOLVED) Force doctype for a single page
 1 Replies
Sort:
Topic is locked
Author Messages

Fabio Pagano



New Member


Posts:
New Member


--
21 Apr 2012 12:34 PM
    In a page i show a google map using google maps javascript api. If the div containing the map canvas is in the form tag, the map doesn't show: <form id="Form1" runat="server"> <div id="map_canvas" style="width:100%; height:100%"></div> </form> If the div is before the form tag, the map shows regularly: <div id="map_canvas" style="width:100%; height:100%"></div> <form id="Form1" runat="server"> </form> I've discovered that the issue is caused by the doctype: if the doctype is: <!DOCTYPE html /> as suggested by google, the map works also if div is in the form tag. The problem is that in my rendered pages i see a more complex doctype, which seems automatically setted by 51 framework: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> In html code i have no doctype tag. Is there a way to force only in this page the doctype to <!DOCTYPE html /> so that the google map is visible also if it is in the form tag? Thank you.
    0

    Murali Setty



    New Member


    Posts:
    New Member


    --
    23 Apr 2012 06:18 AM
    Hi Fabio,

    Yes as you mentioned the Framework logic writes the DOCTYPE based on the browser to ensure the consistent look of the styles on different mobile browsers. Changing the DOCTYPE of mobile page may cause improper control layout or styles rendering so itself we have not exposed any property to override in Mobile.Page calss.

    You can try the following approach to address the issue to override the DOCTYPE set by the Mobile.Page logic.

    public partial class WebForm1 : FiftyOne.Framework.Mobile.Page

    {

            private static readonly Regex _docTypeRegex = new Regex(@"<!DOCTYPE[^>]+>", RegexOptions.Compiled);

            StringWriter _stringWriter = new StringWriter();

            private TextWriter _baseWriter;

            protected override HtmlTextWriter CreateHtmlTextWriter(TextWriter tw)

            {

                _baseWriter = tw;

                HtmlTextWriter tempWriter = new HtmlTextWriter(_stringWriter);

                return base.CreateHtmlTextWriter(tempWriter);

            }

            protected override void Render(System.Web.UI.HtmlTextWriter writer)

            {

                base.Render(writer);

                string pageOutput = _stringWriter.GetStringBuilder().ToString();

                if (_docTypeRegex.IsMatch(pageOutput) == true)

                    // Replace the existing document type with the new one.

                    pageOutput = _docTypeRegex.Replace(pageOutput, "<!DOCTYPE html />");

                _baseWriter.Write(pageOutput);

            }

    }

    Please let me know if you have any concerns or questions.

    Thanks,
    Murali
    0
    Topic is locked