Solved

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

Posted on 2007-04-10
2
695 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

752 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