A
Anthony Williams
Morning all,
I'm having a wee problem with a project I'm working on at the moment.
I'm leading my company into producing a website, based upon Web
Standards, which will be created using XHTML and CSS, and powered by
ASP.NET.
My first problem, which I'm near to solving, was that ASP.NET doesn't
produce valid XHTML output. We don't want to spend money on third-party
components, and we can't wait for ASP.NET 2.0, so we needed to find a
way to use what we have to produce what we're after.
I've taken to extending the System.Web.UI.Page and
System.Web.UI.HtmlControls.HtmlForm controls (using Liquid Internet's
methods, but converted to VB.NET, from
http://www.liquid-internet.co.uk/content/dynamic/pages/series1article1.aspx)
and after a couple of hiccups with events not firing, and changing
Request.Path to Request.Url.ToString, I've managed to get everything
working.
Except that - if you take a look at the generated XHTML (which isn't
valid yet by the way) - you'll find there is two hidden input fields
called "__VIEWSTATE". One of them lives inside a <div> tag (valid
XHTML), the other does not (invalid XHTML).
Forgive me if I'm asking a question in the realms of newbie-dom, but
I've no idea why two ViewState containers are being generated, and would
really appreciate some help.
For clarity, the default namespace in this project is "Listers.Group",
and the assembly is called Listers.Group.dll.
' --- BEGIN CODE BLOCK - TestForm.aspx ---
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="listers.aspx.vb" Inherits="Listers.Group.Pages.Listers" %>
<%@ Register TagPrefix="XHTML" Namespace="Listers.Group.XHTML"
Assembly="Listers.Group" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title runat="server" id=lgTitle>ListersGroup.co.uk - The largest
privately-owned
motor group in the Midlands!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta name="description" content="" id="lgDescription" runat="server" />
<meta name="keywords" content="" id="lgKeywords" runat="server" />
<link rel="stylesheet" type="text/css" href="inc/css/ListersAll.css"
media="all" title="ListersGroup.co.uk" />
</head>
<body>
<XHTML:Form id="ListersForm" method="post" runat="server">
<div id="Page">
<div id="Header">
<h1>ListersGroup.co.uk</h1>
<!-- A Custom Control normally lives here -->
</div>
<div id="Body">
<div id="Navigation">
<!-- A Custom Control normally lives here -->
</div>
<div id="Content">
<!-- A Custom Control normally lives here -->
<p>A button, to test viewstate and event firing:<br /><asp:button
id="Button1" runat="server" Text="Button"></asp:button></p>
</div>
<div>
<div id="Footer">
<!-- A Custom Control normally lives here -->
</div>
</div>
</XHTML:Form>
</body>
</html>
' --- END CODE BLOCK - TestForm.aspx ---
' --- BEGIN CODE BLOCK - XHTML.vb ---
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.IO
Namespace XHTML
Public Class Page
Inherits System.Web.UI.Page
Public Sub New()
' ...
End Sub ' New
Protected Overrides Function
LoadPageStateFromPersistenceMedium() As Object
Dim Format As New LosFormatter
Dim ViewState As String =
Request.Form("__VIEWSTATE").Trim.ToString
Return Format.Deserialize(ViewState)
End Function ' LoadPageStateFromPersistenceMedium
Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal
ViewState As Object)
For Each c As Control In Me.Controls
If c.GetType.ToString = "Listers.Group.XHTML.Form" Then
Dim Format As New LosFormatter
Dim Writer As New StringWriter
Format.Serialize(Writer, ViewState)
Dim StateContainer As New LiteralControl
StateContainer.Text = _
"<div id=""ViewStateContainer"">" & _
"<input type=""hidden""
name=""__VIEWSTATE"" value=""" & Writer.ToString & """ />" & _
"</div>"
c.Controls.AddAt(0, StateContainer)
End If
Next
End Sub ' SavePageStateToPersistenceMedium
End Class
Public Class Form
Inherits System.Web.UI.HtmlControls.HtmlForm
Public Sub New()
' ...
End Sub ' New
Protected Overrides Sub RenderAttributes(ByVal Output As
System.Web.UI.HtmlTextWriter)
Output.WriteAttribute("id", Me.ID)
Output.WriteAttribute("method", Me.Method)
Output.WriteAttribute("action",
HttpContext.Current.Request.Url.ToString)
End Sub
End Class
End Namespace
' --- END CODE BLOCK - XHTML.vb ---
Thanks in advance for any help!
I'm having a wee problem with a project I'm working on at the moment.
I'm leading my company into producing a website, based upon Web
Standards, which will be created using XHTML and CSS, and powered by
ASP.NET.
My first problem, which I'm near to solving, was that ASP.NET doesn't
produce valid XHTML output. We don't want to spend money on third-party
components, and we can't wait for ASP.NET 2.0, so we needed to find a
way to use what we have to produce what we're after.
I've taken to extending the System.Web.UI.Page and
System.Web.UI.HtmlControls.HtmlForm controls (using Liquid Internet's
methods, but converted to VB.NET, from
http://www.liquid-internet.co.uk/content/dynamic/pages/series1article1.aspx)
and after a couple of hiccups with events not firing, and changing
Request.Path to Request.Url.ToString, I've managed to get everything
working.
Except that - if you take a look at the generated XHTML (which isn't
valid yet by the way) - you'll find there is two hidden input fields
called "__VIEWSTATE". One of them lives inside a <div> tag (valid
XHTML), the other does not (invalid XHTML).
Forgive me if I'm asking a question in the realms of newbie-dom, but
I've no idea why two ViewState containers are being generated, and would
really appreciate some help.
For clarity, the default namespace in this project is "Listers.Group",
and the assembly is called Listers.Group.dll.
' --- BEGIN CODE BLOCK - TestForm.aspx ---
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="listers.aspx.vb" Inherits="Listers.Group.Pages.Listers" %>
<%@ Register TagPrefix="XHTML" Namespace="Listers.Group.XHTML"
Assembly="Listers.Group" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title runat="server" id=lgTitle>ListersGroup.co.uk - The largest
privately-owned
motor group in the Midlands!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta name="description" content="" id="lgDescription" runat="server" />
<meta name="keywords" content="" id="lgKeywords" runat="server" />
<link rel="stylesheet" type="text/css" href="inc/css/ListersAll.css"
media="all" title="ListersGroup.co.uk" />
</head>
<body>
<XHTML:Form id="ListersForm" method="post" runat="server">
<div id="Page">
<div id="Header">
<h1>ListersGroup.co.uk</h1>
<!-- A Custom Control normally lives here -->
</div>
<div id="Body">
<div id="Navigation">
<!-- A Custom Control normally lives here -->
</div>
<div id="Content">
<!-- A Custom Control normally lives here -->
<p>A button, to test viewstate and event firing:<br /><asp:button
id="Button1" runat="server" Text="Button"></asp:button></p>
</div>
<div>
<div id="Footer">
<!-- A Custom Control normally lives here -->
</div>
</div>
</XHTML:Form>
</body>
</html>
' --- END CODE BLOCK - TestForm.aspx ---
' --- BEGIN CODE BLOCK - XHTML.vb ---
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.IO
Namespace XHTML
Public Class Page
Inherits System.Web.UI.Page
Public Sub New()
' ...
End Sub ' New
Protected Overrides Function
LoadPageStateFromPersistenceMedium() As Object
Dim Format As New LosFormatter
Dim ViewState As String =
Request.Form("__VIEWSTATE").Trim.ToString
Return Format.Deserialize(ViewState)
End Function ' LoadPageStateFromPersistenceMedium
Protected Overrides Sub SavePageStateToPersistenceMedium(ByVal
ViewState As Object)
For Each c As Control In Me.Controls
If c.GetType.ToString = "Listers.Group.XHTML.Form" Then
Dim Format As New LosFormatter
Dim Writer As New StringWriter
Format.Serialize(Writer, ViewState)
Dim StateContainer As New LiteralControl
StateContainer.Text = _
"<div id=""ViewStateContainer"">" & _
"<input type=""hidden""
name=""__VIEWSTATE"" value=""" & Writer.ToString & """ />" & _
"</div>"
c.Controls.AddAt(0, StateContainer)
End If
Next
End Sub ' SavePageStateToPersistenceMedium
End Class
Public Class Form
Inherits System.Web.UI.HtmlControls.HtmlForm
Public Sub New()
' ...
End Sub ' New
Protected Overrides Sub RenderAttributes(ByVal Output As
System.Web.UI.HtmlTextWriter)
Output.WriteAttribute("id", Me.ID)
Output.WriteAttribute("method", Me.Method)
Output.WriteAttribute("action",
HttpContext.Current.Request.Url.ToString)
End Sub
End Class
End Namespace
' --- END CODE BLOCK - XHTML.vb ---
Thanks in advance for any help!