Validation ($SCHEMA$): Element ‘html’ and ASP.NET 2010

Posted: April 8th, 2010 | Filed under: ASP.NET

I finally got fed up with “Warning Validation ($SCHEMA$): Element ‘html’” enough today that I spent some time to figure out what was causing all the warnings on every html or even <asp> tag I had in my .aspx pages. Every time I would build my project I would get tons of warnings such as

Validation ($SCHEMA$): Element ‘html’
Validation ($SCHEMA$): Element ‘div’
Validation ($SCHEMA$): Element ‘table’
blah.. on and on they went.

The warnings however were not the problem, it was that IntelliSense would stop working when these were present.

How to Fix it

Crazy enough it seems that the default validation for html in Visual Studio 2010 is.. nothing. So nothing validates.

I knew that Microsoft didn’t care about web standards but damn.

Go to Tools > Options > Text Editor > HTML > Validation > select one of the options.

I also disabled the show errors checkbox, mainly because I really don’t care about everything that does not validate.


ASP.NET/C# Prompt a Save Dialog Box to Download a File

Posted: May 15th, 2009 | Filed under: ASP.NET | Tags:

To save you all (as well as my future self) the trouble of searching all over the place just to find terrible answers on almost every form post out there. Here is a small ASP.NET/C# code snippet that will prompt the user with the save/open dialog box to download a file.

String FileName = "FileName.txt";
String FilePath = "C:/...."; //Replace this
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "text/plain";
response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ";");
response.TransmitFile(FilePath);
response.Flush();
response.End();

For more content types check our http://en.wikipedia.org/wiki/MIME_type#List_of_common_media_types


Input Data to Display Newlines in ASP.NET

Posted: February 14th, 2009 | Filed under: ASP.NET, C Sharp | Tags:

In asp.net input taken from a plain text box will not display newline characters (Hitting the enter key) when outputting to the browser.

So for example you have a text box that users can input text into, they put a couple paragraphs in it and submit that data to the database. If you just strait output the content to the browser you will see one giant blob of text. So how can you fix this?

By converting the newline to a html
tag we can fix the problem. So with a little c# function we have the trick done.

public String FixLabelOutput(String val) {
    return val.Replace(Environment.NewLine, "<br />");
}

As you see our function simple returns all newlines as <br /> which will fix the way it is outputted.

In the aspx page you need to have this to display the corrected text. This of course can be placed in a label or just strait printed.

<%# FormatHtml(Eval("TextInfo").ToString()) %>