Solved

ASP.NET code injection into web/html control causes W3C markup validation failure

Posted on 2007-04-10
2
690 Views
Last Modified: 2013-11-19
Hello,

First off, my goal is to have my ASP.NET 2.0 web application to pass the W3C markup validation test using this DOCTYPE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

I have encountered the following problem, and its killing me. When I add a button control (either <ASP:BUTTON... /> or <input button... runat=server... /> ), and add client-side javascript in the code-behind to the client-onclick event handler-- asp.net injects code that causes the page to fail the W3C markup validation test.

The actual button control currently looks like this:
<input type="button" ID="button_delete" onserverclick="fnDelete" Value="Delete Contact" Runat="server" />

My code that adds client side script (in code behind) to the button looks something like this:
button_delete.Attributes.Add("onclick", "fnDeleteItClientSide());");

When the page is run-- the button control ends up looking like this:
<input language="javascript" onclick="fnDeleteIt(); __doPostBack('cntrlContact$button_delete','')" name="cntrlContact$button_delete" type="button" id="cntrlContact_button_delete" value="Delete Contact" />

This is being injected in my button: language="javascript" .... and this code injection is causing my page to fail the W3C validation test. HOW DO I GET RID OF THIS language="javascript"-- HELP!

Thanks!
0
Comment
Question by:NeonSnake
2 Comments
 
LVL 15

Accepted Solution

by:
igor_alpha earned 500 total points
ID: 18886049
Hi NeonSnake,
You can rid injection by using button server control. Furthemore, button server control in your case have more sense.
Just change "input type button" with "asp:button":
<asp:Button ID="button_delete" runat="server" Text="Delete Contact" UseSubmitBehavior="false" />
Leave codebehind unchanged and you see that language="javascript" string now disappear...
0
 

Author Comment

by:NeonSnake
ID: 18890625
Thanks-- this works.

Funny-- I thought I tried that already, guess not.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Separate a number and letter from a string 25 26
String manipulation 15 49
Spacing between controls 4 16
Copy/Clone an object. 9 15
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now