views:

267

answers:

1

Question: Is there a way to detect what XHtml conformance setting a particular ASP.Net web page is being generated using at run time (without reference to the web.config).

Background: We have ASP.NET web pages which need to work under different XHtml Conformance modes - mostly Legacy (Sorry Mum), but some which use Transitional to enable AJAX Update Panels etc. to function correctly.

We are using location tags in the web config to override the conformance mode for individual web pages.

<system.web>

    <xhtmlConformance mode="Transitional" />

</system.web>

But we came across an issue, where upon the first display the web page - none of links or buttons worked correctly - the first button click was always ignored, but any subsequent clicks were okay.

Have traced this to doing a Server.Transfer from a Legacy Web Page to the Transition Web Page - I assume the transitional page wasn't actually rendered as Transition and therefore the first postback wasn't in the correct format and the web server went "not like that, like this!". I assume similar issues may exist when Server Transferring from Transition pages back into Legacy pages.

Response redirects do work ok, but unfortunately Server Transfers are commonly used within our application and some of the transfers are using data exchange from the previous page - which makes a blanket replacements of server transfers impossible.

So I am looking into whether we can automatically and generically force an extra postback or maybe a redirect on initial display when we are found to be being rendered in the wrong mode (assuming that is the issue). But am needing to detect what mode we are being rendered in - and asking the config would always come up with the same answer that in this case may not necessarily be the right answer.

Cheers if anyone can help.

A: 

Hi,

I'm encountering a similar issue at the moment and proved that the problem is that the XhtmlConformance isn't reset on the Server.Transfer - this was done using some reflection on the Page class to obtain the XhtmlConformance property.

I was thinking of a similar solution too, however I believe the following issues exist:

  1. If you are storing any of the cross page post data in ViewState, that'll be lost on the Response.Redirect, therefore you need to store it in session. This then leads to the question "why obtain the data from the cross page post"?
  2. This may lead to bugs where this auto redirect behaviour may introduce other unforeseen issues that may not be apparent and the redirect masks it (e.g. if business processing happens before the Redirect call).

Are any of your JS functions obtaining controls through their name? If not the ID property doesn't change, so if you are grabbing everything this way then there's no reason why you can't set the conformance mode to Transitional across the board. From some initial tests Server.Transfer works then.

If that isn't possible then I think the safest approach is to deal with each page on a case by case basis that is directed to/from the AJAX page and convert it to use Response.Redirect.

The only other approach I can think of is to use JavaScript to render the UI updates. However that's more work than a simple UpdatePanel (though it does perform better).

spooner
Cheers to Spooner, his comment in the 1st para that was done using some reflection on the Page class to obtain the XhtmlConformance property, gave me enough info to track down how it's done - see http://forums.asp.net/t/1451823.aspx for the implementation.
trekerb