If IsMobileDevice Then generate pointless TABLES in my html! Why?

Last post 11-13-2009 9:07 AM by SKT_01. 10 replies.

Sort Posts:

  • If IsMobileDevice Then generate pointless TABLES in my html! Why?

    11-12-2009, 7:53 AM
    • Member
      73 point Member
    • djpeanut
    • Member since 02-21-2006, 10:07 PM
    • Posts 31

    I've been wrangling with ASP.NET's outdated mobile browser detection system for a while and I've finally replaced it with WURFL's up-to-date model using WURFL.NET from http://wurfl.marg.si/. At last I can adapt my output properly. I thought.

    BUT I've just discovered via the W3C validator and ready.mobi that ASP.NET has decided to wrap my entire page inside the aspnet <form> tags in a completely pointless <table><tr><td>! (In the usual suspect desktop browsers it's all wrapped in an equally-pointless <div>, but I can live with that.)

    I despair sometimes. Surely presentational tables are even more ill-advised when it comes to mobile browsers? How can I stop ASP.NET from being so flatulent?

    Cheers,

    Tom


    Filed under: ,
  • Re: If IsMobileDevice Then generate pointless TABLES in my html! Why?

    11-12-2009, 8:07 AM
    Answer
  • Re: If IsMobileDevice Then generate pointless TABLES in my html! Why?

    11-12-2009, 8:12 AM
    • Member
      73 point Member
    • djpeanut
    • Member since 02-21-2006, 10:07 PM
    • Posts 31

    Thanks, I'll add that to my reading list.

    Now, does anyone have a practical work-around that doesn't involve rewriting an entire website from the ground up to remove a single <table>?

  • Re: If IsMobileDevice Then generate pointless TABLES in my html! Why?

    11-12-2009, 8:17 AM
    • Star
      12,629 point Star
    • docluv
    • Member since 06-29-2002, 11:16 PM
    • Willow Spring NC
    • Posts 1,997
    • ASPInsiders
      TrustedFriends-MVPs

     You could write a custom HttpModule that will evaluate the markup being sent to the browser and remove the table from the stream before it is sent down the wire.

  • Re: If IsMobileDevice Then generate pointless TABLES in my html! Why?

    11-12-2009, 8:30 AM
    • Member
      73 point Member
    • djpeanut
    • Member since 02-21-2006, 10:07 PM
    • Posts 31

    That sounds viable.

    As much as I'd love to be working with a site built on MVC, this is an existing Web Forms site that needs adapting for broad mobile browser compatibility. MVC is definitely my next learning topic after this mess. Like you say on your site, Web Forms seems to have dropped clean HTML, CSS and JS into a big vat of lumpy code porridge.

  • Re: If IsMobileDevice Then generate pointless TABLES in my html! Why?

    11-12-2009, 8:41 AM
    Answer
    • Participant
      1,921 point Participant
    • SKT_01
    • Member since 04-17-2007, 5:31 AM
    • Germany
    • Posts 430

    Hello Tom,

    it would be interesting to know which controls you are using and why your "entire page inside the aspnet <form> tags" is wrapped in a HTML table.

    The reason for such behavior is probably the adaptive rendering mechanism of ASP.NET. If you could provide such information (code or URL) I can perhaps help you.

    Thank you.

  • Re: If IsMobileDevice Then generate pointless TABLES in my html! Why?

    11-12-2009, 8:48 AM
    Answer
    • All-Star
      60,652 point All-Star
    • anas
    • Member since 09-21-2006, 4:31 AM
    • Palestinian Territory, Occupied
    • Posts 6,847
    • Moderator

    djpeanut:
    BUT I've just discovered via the W3C validator and ready.mobi that ASP.NET has decided to wrap my entire page inside the aspnet <form> tags in a completely pointless <table><tr><td>!

    I think you will need to create a custom ResponseFilter and use the Regx or string operations to find the <table> tag and replace it before asp.net send the stream to the client browser.

    Some reources about the Filters:

    http://msdn.microsoft.com/en-us/library/system.web.httpresponse.filter.aspx

    http://authors.aspalliance.com/aspxtreme/sys/Web/HttpResponseClassFilter.aspx

    http://ondotnet.com/pub/a/dotnet/2003/10/20/httpfilter.html

    Regards,

    Anas Ghanem | Blog

  • Re: If IsMobileDevice Then generate pointless TABLES in my html! Why?

    11-12-2009, 10:08 AM
    • Member
      73 point Member
    • djpeanut
    • Member since 02-21-2006, 10:07 PM
    • Posts 31

    SKT_01:

    Hello Tom,

    it would be interesting to know which controls you are using and why your "entire page inside the aspnet <form> tags" is wrapped in a HTML table.

    The reason for such behavior is probably the adaptive rendering mechanism of ASP.NET. If you could provide such information (code or URL) I can perhaps help you.

    Thank you.

    I'm sure the adaptive rendering mechanism you speak of is to blame. My code is pretty uncomplicated. This is the output when browsing with a desktop UA:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>***</title>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <link type="text/css" href="/resources/reset.css" rel="stylesheet" media="all" />
    <link type="text/css" href="/resources/screen.css" rel="stylesheet" media="Screen" />
    <link type="text/css" href="/resources/print.css" rel="stylesheet" media="print" />
    <link type="text/css" href="/resources/handheld.css" rel="stylesheet" media="handheld" />
    <script type="text/javascript" src="/resources/main.js"></script>

    <link type="text/css" href="/resources/homepage.css" rel="stylesheet" media="Screen" />
    <meta id="ctl00_HeadContentPlaceHolder_metaKeywordsTag" name="keywords" content=""></meta>
    <meta id="ctl00_HeadContentPlaceHolder_metaDescriptionTag" name="description" content=""></meta>

    <!--[if lte IE 7]>
    <link rel="stylesheet" type="text/css" href="/resources/ie7.css" />
    <![endif]-->
    <!--[if lte IE 6]>
    <script language="javascript" type="text/javascript" src="/resources/ie6.js"></script>
    <link rel="stylesheet" type="text/css" href="/resources/ie6.css" />
    <![endif]-->
    </head>
    <body>
    <form name="aspnetForm" method="post" action="/default.aspx" id="aspnetForm"><div>
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDw...


    .... but notice the difference when I use a mobile browser (or the W3C validator!):


    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>***</title> <link type="text/css" href="/resources/reset.css" rel="stylesheet" media="Screen, print" /> <link type="text/css" href="/resources/screen.css" rel="stylesheet" media="Screen" /> <link type="text/css" href="/resources/print.css" rel="stylesheet" media="print" /> <link type="text/css" href="/resources/handheld.css" rel="stylesheet" media="handheld" /> <script type="text/javascript" src="/resources/main.js"></script> <link type="text/css" href="/resources/homepage.css" rel="stylesheet" media="Screen" /> <meta id="ctl00_HeadContentPlaceHolder_metaKeywordsTag" name="keywords" content=""></meta> <meta id="ctl00_HeadContentPlaceHolder_metaDescriptionTag" name="description" content=""></meta> <!--[if lte IE 7]><link rel="stylesheet" type="text/css" href="/resources/ie7.css" /> <![endif]--><!--[if lte IE 6]><script language="javascript" type="text/javascript" src="/resources/ie6.js"></script> <link rel="stylesheet" type="text/css" href="/resources/ie6.css" /> <![endif]-->
    </head> <body>
    <form name="aspnetForm" method="post" action="/default.aspx" id="aspnetForm">
    <table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td>
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMT...


    So I guess I'm off on a trip to somehow filter out that table markup...

  • Re: If IsMobileDevice Then generate pointless TABLES in my html! Why?

    11-12-2009, 10:24 AM
    • Participant
      1,921 point Participant
    • SKT_01
    • Member since 04-17-2007, 5:31 AM
    • Germany
    • Posts 430

    Tom,

    which control are you using within the ASP.NET form? A Data control like a GridView or other controls?

  • Re: If IsMobileDevice Then generate pointless TABLES in my html! Why?

    11-13-2009, 2:18 AM
    • Member
      73 point Member
    • djpeanut
    • Member since 02-21-2006, 10:07 PM
    • Posts 31

    I am using a Repeater on a couple of pages, otherwise there are no databound controls present. Repeater or no, it doesn't seem to make any difference.

  • Re: If IsMobileDevice Then generate pointless TABLES in my html! Why?

    11-13-2009, 9:07 AM
    • Participant
      1,921 point Participant
    • SKT_01
    • Member since 04-17-2007, 5:31 AM
    • Germany
    • Posts 430

    The rendering of a table might be caused by other controls than a repeater, e. g. a Panel control which renders a div or a table depending on the device. Therefore I asked you which controls you are using.

Page 1 of 1 (11 items)