...

View Full Version : asp.net not w3c compliant



dominicall
10-08-2003, 08:41 PM
Anyone know if there's a solution to this...

I always aim to have all pages I build validate with the w3c validation, but since I've started using .NET the framework adds the name tags to the form tag which makes it non compliant.

Is there any way around this?

Thanks

dominicall

angiras
10-09-2003, 04:59 AM
you must build your own framework

for exemple to remove the name="" to the form you must overrides RenderAttributes

Public Class myHtmlForm : Inherits System.Web.UI.HtmlControls.HtmlForm

Protected Overrides Sub RenderAttributes(ByVal output As HtmlTextWriter)
output.WriteAttribute("id", Me.ID)
output.WriteAttribute("method", Me.Method)
output.WriteAttribute("action", YourFullPathMethod)
End Sub

same thing for the page ect ....

whammy
10-09-2003, 05:22 AM
Now I just have to translate that to C#... looks like it isn't too hard though.

I totally agree with you dominicall, it's a pain... but what's worse (er, maybe - you'd think with all of the XML and the fact that Visual Studio .NET actually writes MOSTLY correct code, they would have gone all the way... :rolleyes: ) is dealing with other people's code that looks like:

<font face = arial size = -1><b>Argh</b></font>
<br>

... no stylesheets, no quotes around element attributes, extra spaces, unclosed tags, and to add to the frustration they don't indent their code at all. :eek:

I think it's a crime that the code works at all in any browser. I think browsers need to start getting MUCH stricter - sure it will break a lot of pages; which will force people to learn how to code correctly, or use a tool that writes compliant code, if they care about anyone looking at their site anyway...

What's kind of cool is that a colleague of mine developed a site in .NET and if you try to open the page in Netscape 4.x it actually just closes the browser; no errors or anything, it just disappears.

I've tried to duplicate that effect for fun to no avail. :rolleyes:

P.S. Angiras, that's interesting that you're using ByVal - isn't that already the default in .NET, which makes it unnecessary using VB.NET as opposed to classic ASP?

angiras
10-09-2003, 05:35 AM
yes it is terrible not to get directly XHTML


but to build your own framework (with own controls) is normal
the basic framework is .... basic

with inheritence it is so easy :


----------------------------------

Namespace Angiras.FrameWork.Pages

Public Class Page : Inherits System.Web.UI.Page

Private Const _XMLVERSION As String = "<?xml version=""1.0"" encoding=""iso-8859-1"" ?>"

Private Const _DOCTYPE As String = "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"">"
Private Const _HTML As String = "<html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""fr"" lang=""fr"">"

Protected Head As Ang_CtrlC.HeadContent
Protected Form As Ang_CtrlB.HtmlForm
Protected _layout As Ang_CompCom.Layout

Public Sub New()
MyBase.New()
End Sub


Protected Overrides Sub OnInit(ByVal e As System.EventArgs)

Head = New Ang_CtrlC.HeadContent

Me.Controls.Add(Head)
Me.Controls.Add(Form)

_layout = New Ang_CompCom.Layout 'to load the content for each page
Form.Controls.Add(_layout)

If Not HttpContext.Current.User.Identity.IsAuthenticated Then
_layout.AddToBody(New Ang_Comp.Login.Run)
Else
_layout.AddToBody(New Ang_CompCom.Content)
End If

Dim _ct As Ang_U.ComponentType = Me.GetComponentType()

End Sub

Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)
Form.Controls.Add(CType(obj, Control))
End Sub

Protected Overrides Sub render(ByVal writer As HtmlTextWriter)

writer.WriteLine(_XMLVERSION)
writer.WriteLine(_DOCTYPE)
writer.WriteLine(_HTML)
writer.WriteLine("<head>")
Head.RenderControl(writer)
writer.WriteLine("</head>")
writer.WriteLine("<body>")
Form.RenderControl(writer)
writer.WriteLine("</body>")
writer.WriteLine("</html>")

End Sub

End Class

End Namespace

---------------------------------------

angiras
10-09-2003, 05:43 AM
P.S. Angiras, that's interesting that you're using ByVal - isn't that already the default in .NET, which makes it unnecessary using VB.NET as opposed to classic ASP?

you must write ByVal with vbnet (or ByRef)

unnecessary using VB.NET as opposed to classic ASP ??!!
I don't understand ! you cannot compare the very poor asp and ASP NET

6 object in the first case
4000 in the second + inheritence + POO


-----------------

I NEVER use visual Studio as designer , I even doesn't open it

if you prepare your strict XHTML models and your valid CSS, then as templates (ascx files) or inheritence (my way) you will get easily what you want

I use NET as a code generator to produce HTML pages with contents

whammy
10-09-2003, 05:49 AM
From what I've used of Visual Studio .NET, I'm quite sure I'm going to be doing the same thing... it's basically a bloated version of FrontPage in that regard.

:rolleyes:

+ POO ? LOL! I think you mean OOP... ;)

angiras
10-09-2003, 05:56 AM
yes sorry in french it is POO :-))

developpers who change from asp to asp net are generally using the same way of coding that with asp 3, in that case it is better to keep asp 3 coding , and to avoid headhake ;-))

whammy
10-09-2003, 06:01 AM
Not me, I decided to use C# since it's more like Java, JavaScript, C, C++ etc. Personally I'd rather have a few headaches at first, to save more headaches in the long run!

I prefer the stricter (and more structured) syntax, and to me VBScript has always been horrible because it allows for _very_ sloppy coding.

Actually the changes from VBScript/VB to VB.NET are harder for me to learn than just using C# from scratch. But hey, it's all about what's most comfortable for you, anyway.

;)

angiras
10-09-2003, 06:14 AM
yes I'd like one day to jump to C# ... new NET features are 80% for it

but with C# I'm all the time lost with
}
}
}
}
}

you don't know where you are

I was programming with VB 6 and found also so limited VB script , .... specially without GoTo

whammy
10-09-2003, 06:22 AM
Really C# is just like JavaScript... at least to me.


function whatever()
{
//do stuff here
}


... and even JavaScript can inherit stuff, and you can add things using prototyping in JavaScript like:


String.prototype.trim = function()
{
return this.replace(/^\s+/,'').replace(/\s+$/,'');
}


That emulates the old Trim() function in VBScript (client-side) exactly, and you can use it like:

mystring = mystring.trim();

... when it comes to "knowing where you are" that's what indentation is for! And as much as I hate some aspects of Visual Studio .NET, it allows you to step through the code in debug mode as it executes; which is pretty cool... that way you can easily follow the program flow.


if (this == whatever)
{
if (this2 == whatever2)
{
//whatever!
}
}
else
{
//else
}

angiras
10-09-2003, 06:38 AM
yes with indenting .... that's true

you have also very practicle #region in VS

yes ... I must try C# one day

but I was never good with javascipt and never learnt any C or javalike langage

just started with vb 4

whammy
10-09-2003, 06:59 AM
Then you have to! It's much nicer really, I use VbScript every day and I hate it, especially how sloppy it CAN be, although I try not to be.

But there are still stupid things that happen, especially in classic ASP. For instance, I did this today!:

string = string & rs("somefield1") & _
string = string & rs("somefield2") & _
string = string & rs("somefield3") & _
string = string & rs("somefield4")

Looking back on it I was stupid, since I was already adding to the string I didn't need to use "& _", really it was a copy and paste mistake; I made the mistake once, and kept making it over and over...

... but, it didn't throw an error! Instead it turned the variable "string" into a boolean value of FALSE (don't ask me why)! To me, that's unacceptable in a programming language, because it should have thrown a syntax error.

Instead, it took me a while to figure out that I had used two methods of concatenation together, and the error wasn't showing what the real problem was, or anywhere near it, since there was NO ERROR MESSAGE!

At least in C, C#, Java, JavaScript, etc. it probably would have generated an error message like "You are a moron" or something. ;)

angiras
10-09-2003, 07:13 AM
but I never use any more vb scrip

in sted of

string = string & rs("somefield1") & _
string = string & rs("somefield2") & _
string = string & rs("somefield3") & _
string = string & rs("somefield4")

you can do

s += any

s = String.Format(varString, any1, any2, any3)

mStringBuilder.Append(any)
mStringBuilder.AppendForma(varString, any1, any2, any3)

----------------------------------------------------

also one thing that I hate with Javalike langage is Case Sensitive

if you write : string in VS it will correct it for : String

with C# you get an error


I just want to change for C# just because it seems to be more supported by Microsoft in the futures versions

for me VB NET coding is perfect (nearlly :-))

dominicall
10-09-2003, 07:22 AM
Thanks for the replies guys - much appreciated... :D

Think I'll have a look at angiras' solution... although the only compliancy error from all the code that VS.NET created was was with the adding of the name attribute to the form tag.

Interesting discussion though.

One thought whammy - and I'm not sure how much influence you have over this... was wondering whether it's worth setting up a different forum for .NET instead of wrapping it up with ASP. It's such a wide topic area and imvho probably deserves it.

dominicall

angiras
10-09-2003, 07:29 AM
with Overrides RenderAttributes and Render method
you control the output of all

Caffeine
10-09-2003, 07:42 AM
Originally posted by dominicall
... was wondering whether it's worth setting up a different forum for .NET instead of wrapping it up with ASP. It's such a wide topic area and imvho probably deserves it.

More and more people migrate to asp.Net and since it is completely different from the old asp, I think it needs a separate forum. Basically, the only think asp.Net and classic asp has in common is the 3 letters A S P.

I plan to migrate to asp.Net soon, I too dislike VBScript, but at the same time i'm afraid I will be having major troubles with C# and the way of thinking in asp.Net. But I like to think that eventually the pain will pay off :D


... hmm
to make asp.Net generate valid & compliant code, does one need to redefine all classes (or whatever they are called) or is it just a few ??

angiras
10-09-2003, 07:49 AM
to make asp.Net generate valid & compliant code, does one need to redefine all classes (or whatever they are called) or is it just a few ??

they are no so many controls

Page (with Head Body and HtmlForm)
textBoxes
ListBoxes
radio, check, buttons ..

I never use the dataGrid , it is a wonderfull catastrophy

I use a repeater or a datalist or I just Implements IRepeater, and with ItemTemplates you control also the grid totally , not any more border="0"

I never use textBox directly or together with validators, I have a control TextBoxTyped : inherits TextBox

an Enum for the types

then I just do

as new myTBtyped(numeric)




once you have done your basic controls .... you just take a beer :-))

angiras
10-09-2003, 08:03 AM
possibilities
to give an exemple of possibilities :

in the moment I am building a big Intranet for a company
with authentification (users, roles) possibility of 4 different dataBase (Acces SQL Oracle DB2)

in the webSite itself there is ONE page : default.aspx

in this page one line :
<%@ Page Codebehind="default.aspx.vb" Inherits="HelpDesk.WebSite.MainPage"%>

in the default.aspx.vb :

Imports HelpDesk.FrameWork

Namespace HelpDesk.WebSite
Public Class MainPage : Inherits HelpDesk.FrameWork.Pages.Page
Public Sub New()
MyBase.New()
End Sub
End Class
End Namespace


that's all !

no global.asax


the web.config
CSS and JS files , and images



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum