Results 1 to 9 of 9

Thread: ASP.NET 2.0 and XHTML Strict

  1. #1

    Thread Starter
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292

    ASP.NET 2.0 and XHTML Strict

    Hello

    I have two problems (I hope they are not serious)
    Say I have the following code that needs to validate to XHTML 1.0 Strict

    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    
    <head>
    	<!-- TITLE BEGINS --><title>Example</title>
    	<!-- TITLE ENDS -->
    
    	<!-- META STARTS-->
    	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    	<link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
    	<link rel="schema.dcterms" href="http://purl.org/dc/terms/" />
    	<meta name="dc.title" content="Example"/>
    
    	<!-- META ENDS -->
    
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        Hello World!!!
        </div>
        </form>
    </body>
    </html>
    I though all I would need to do is add this to the web.config so that it would validate to XHTML Strict

    Code:
    <xhtmlConformance mode="Strict" />
    but when I tried to validate with the W3C validator I got the message that the page tentatively passed validation and that overridding needed to take place.

    W3C validator told there was a Character Encoding Override in effect!

    and

    The detected character encoding "iso-8859-1" has been suppressed and "utf-8" used instead.

    Is it possible to validate to XHTML strict using iso-8859-1?

    Another thing is how do I get around the __viewstate that starts with the underscore? I know that ASP.NET 2.0 puts a div around it so that a block element holds the input (W3C validator is happy) but CSE Validator tells me that an underscore cannot start the value of an id or name attribute

    Is there a work around for this and also when I take the server output from the view source and copy it to an html extension file, it validates. Is this a problem with the aspx extension?

    I am not allowed to change the encoding.

    Thanks in advance

    bsw
    Last edited by bsw2112; Mar 26th, 2007 at 05:25 PM.

  2. #2

    Thread Starter
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292

    Re: ASP.NET 2.0 and XHTML Strict

    I found a sulution to the encoding overwrite.
    In web.config, I put this

    Code:
    <system.web>
          <globalization requestEncoding="iso-8859-1" responseEncoding="iso-8859-1"/>
    
    ...
    <system.web>
    It seems that the default is uft-8

    The only thing left is the underscore in __viewstate
    I am not very optimistic


    bsw

  3. #3
    Frenzied Member TomGibbons's Avatar
    Join Date
    Feb 2002
    Location
    San Diego, CA Previous Location: UK
    Posts
    1,345

    Re: ASP.NET 2.0 and XHTML Strict

    If you're not having much luck with the web.config, try doing it manually by having (change UTF-8 as appropriate)
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    at the top of your HTML and
    Code:
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
    in the document HEAD. This is stated in the W3C recommendations and will validate.

  4. #4

    Thread Starter
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292

    Re: ASP.NET 2.0 and XHTML Strict

    Thanks Tom,

    Specifying iso-8859-1 in web.config worked.
    I need to use iso-8859-1 so changing to utf-8 is not an option.

    Now I am working on getting around the underscore in __viewstate

    I am looking at this article (http://www.123aspx.com/redir.aspx?res=30966) that appears to provide a solution by making use of a literal control. Not sure what this is but will so find out

    bsw

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: ASP.NET 2.0 and XHTML Strict

    You need that viewstate hidden field for your ASP.NET controls on the page to work. But I did not know that this could be worked around as well, so that's a great link you've posted.

  6. #6

    Thread Starter
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292

    Re: ASP.NET 2.0 and XHTML Strict

    The problem is that I can't do anything manipulate the form and the postback and state retention isn't working. What am doing wrong?

    I am a weak programmer especially with C# so perhaps this has something to do with my problems but for the time being I cannot get this to work in a .NET 2.0 environment

    my default.aspx

    Code:
    <%@ Page Language="C#" AutoEventWireup="True" Inherits="Liquid.Tutorial.CustomPage" %>
    <%@ Register TagPrefix="Liquid" Namespace="Liquid.Tutorial" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    
    <head>
    	<!-- TITLE BEGINS --><title>Example</title><!-- TITLE ENDS -->
    
    	<!-- META DATA BEGINS -->
    	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    	<link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
    	<link rel="schema.dcterms" href="http://purl.org/dc/terms/" />
    	<meta name="dc.title" content="Example"/>
    	<!-- META DATA ENDS -->
    
    </head>
    <body>
    		<h1>Replacement ASP.NET Form</h1>
    		
    		<Liquid:CustomForm id="myId" method="post" runat="server">
    		<div>
                <asp:Literal id="inputViewState" runat="server"/>
                <asp:Label ID="someLabel" runat="server"></asp:Label>
               	<input type="text" name="dd" id="dd" runat="server"/>
                <asp:Panel ID="someDiv" runat="server">
                </asp:Panel>	
    			<input type="submit" runat="server"/>
    		</div>
            
            </Liquid:CustomForm>
    		<p><asp:Literal id="outputText"	runat="server"/></p>
    	
    	</body>
    </html>
    Here is my CustomPage.cs code

    Code:
    using System;
    using System.IO;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    
    /// <summary>
    /// Summary description for CustomPage
    /// </summary>
    namespace Liquid.Tutorial
    {
        public class CustomPage : Page
        {
            protected Literal inputViewState;
            protected Literal outputText;
            protected Label someLabel;
            protected HtmlInputText dd;
            protected Panel someDiv;
            protected HtmlGenericControl someParagraph;
            
            public CustomPage()
            {
            }
            protected override Object LoadPageStateFromPersistenceMedium()
            {
    	        LosFormatter format = new LosFormatter();
    	        String viewState = HttpContext.Current.Request.Form["__VIEWSTATE"].ToString();
    	        return format.Deserialize(viewState);
            }
            protected override void SavePageStateToPersistenceMedium(Object viewState)
            {
    	        LosFormatter format = new LosFormatter();
    	        StringWriter writer = new StringWriter();
    	        format.Serialize(writer, viewState);
    	        this.inputViewState.Text = "<input type=\"hidden\" name=\"VIEWSTATE\" value=\"" + writer.ToString() + "\"/>";
             }
            protected void Page_Load(Object sender, EventArgs e)
            {
      
    [b]//this does not work[/b]         
    Label someLabel = new Label();
                someLabel.Text = "Text in a label";
    //this does not work
                HtmlGenericControl someParagraph = new HtmlGenericControl("p");
                someParagraph.InnerText = "Paragraph text goes here";
    
                Panel someDiv = new Panel();
                someDiv.Controls.Add(someParagraph);
                            
               if (Page.IsPostBack)
                {
    
                
    //this does not work
    //HtmlInputText dd= new HtmlInputText();
                //outputText.Text = dd.Value;
    
    //this does            
    outputText.Text = this.Request.Form.Get("dd");
                }
            }
      
        }
        public class CustomForm : HtmlForm
        {
            public CustomForm()
            {
            }
            protected override void RenderAttributes(HtmlTextWriter output)
            {
                output.WriteAttribute("id", this.ID);
                output.WriteAttribute("method", this.Method);
                output.WriteAttribute("action", HttpContext.Current.Request.Path);
            }
           protected override void RenderChildren(HtmlTextWriter output)
            {
                foreach (Control c in base.Controls)
                {
                    c.RenderControl(output);
                }
            }
        }
    }
    I am trying to get information from that text field (dd) but cannot do it if I check for postback. (postback does not work for me)
    The only way I get something back from dd is if I remove the postback condition and even then I can only get at it with

    Code:
    outputText.Text = this.Request.Form.Get("dd");
    I tried this
    Code:
     HtmlInputText someTextBox = new HtmlInputText();
     outputText.Text = someTextBox.Value;
    but it didn't work

    Other problems I am having is adding controls dynamically to the form:
    Code:
        HtmlGenericControl someParagraph = new HtmlGenericControl("p");
        someParagraph.InnerText = "Paragraph text goes here";
    
        Panel someDiv = new Panel();
        someDiv.Controls.Add(someParagraph);

    I also tried to add a textbox server control to the defaul.aspx page and it complained that it needs to be put in between <form runat="server"> (which I don't have)
    Code:
    <body>
    		<h1>Replacement ASP.NET Form</h1>
    		
    		<Liquid:CustomForm id="myId" method="post" runat="server">
    		<div>
                <asp:Literal id="inputViewState" runat="server"/>
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    			<input type="submit" runat="server"/>
    		</div>
            
            </Liquid:CustomForm>
    		<p><asp:Literal id="outputText"	runat="server"/></p>
    	
    	</body>
    In short I don't see the point of doing this as it seems like the state is not preserved and the postback isn't working...

    mendhak PLEASE HELP!!

    I am adding my test project (zip)
    bsw
    Attached Files Attached Files
    Last edited by bsw2112; Mar 28th, 2007 at 10:44 AM.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: ASP.NET 2.0 and XHTML Strict

    Alright, I tried it out, but I never could get your sample to work. Then again I didn't spend a lot of time on this due to lack of it. Has this actually worked for you?

  8. #8

    Thread Starter
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292

    Re: ASP.NET 2.0 and XHTML Strict

    Hi mendhak
    Thank you for your response.

    Alright, I tried it out, but I never could get your sample to work...
    Not sure if you mean it doesn't run or it doesn't do what I said it's doing. The example runs. It just doesn't do what the guy's tut said. (his example is .net 1.1 and I am trying to make it work in .net 2.0 - perhaps this is why I am having problems...)

    I put it up here for you to see it
    http://www.wawryn.com/WebSite1/Default.aspx

    I am also adding a new zip with the modified code to see outputs better(the green and red output) although you never see the red as it depends on isPostBack that isn't working.


    If you look at the source code you will notice that I modified the viewstate hidden input name and id from __viewstate to viewstate
    bsw
    Attached Files Attached Files
    Last edited by bsw2112; Mar 29th, 2007 at 11:50 AM.

  9. #9

    Thread Starter
    Hyperactive Member bsw2112's Avatar
    Join Date
    Nov 2001
    Location
    ottawa, canada
    Posts
    292

    Re: ASP.NET 2.0 and XHTML Strict

    hi mendhak
    were you able to make the new code run?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width