Solved

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

Posted on 2007-04-10
2
694 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

735 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