While creating a few mobile forms for my West Wind Web Store applications that manage the remote order management portion of the Admin interface I realized that it's pretty tough to debug the HTML output from a specific device. The issue is that if you hit the mobile page from a SmartPhone, a Windows Web Browser or a WAP phone you get different output. I'm doing this with VS.NET 2005 and well there are a few problems with the output generated.

 

So the question is how do you debug the output for a specific device? For example, on the SmartPhone HTML output there's no view source. To facilitate this process I decided to add a method to my MobilePage subclass that makes it easy for me to capture the output and write it to disk on the server.

 

protected string SavePageOutput(HtmlTextWriter writer, string OutputFile)

{

    // *** Write the HTML into this string builder

    StringBuilder sb = new StringBuilder();

    StringWriter sw = new StringWriter(sb);

 

    MobileTextWriter hWriter = (MobileTextWriter) this.Adapter.CreateTextWriter(sw);

    base.Render(hWriter);

 

    // *** store to a string

    string PageResult = sb.ToString();

 

    // *** Write it back to the server

    writer.Write(PageResult);

 

    if (OutputFile != null && OutputFile != "")

    {

        StreamWriter ssw = new StreamWriter(OutputFile);

        ssw.Write(PageResult);

        ssw.Close();

    }

   

    return PageResult;

} 

 

To capture the page output all I have to do now is to call this method. To facilitate this process I use a page level define:

 

protected override void Render(HtmlTextWriter writer)

{

#if (SAVEPAGEOUTPUT)

    this.SavePageOutput(writer, Request.PhysicalApplicationPath +

                        "admin\\mobile\\ShowInvoices_Output.htm");

#else

    base.Render(write)

#endif

}

 

The same approach works for normal Web Pages as well BTW. Among other things this approach can allow you to save the output from every generated page into a store of your choice.