Solved

W3C Validating an ASP.NET ImageButton control

Posted on 2008-10-28
5
869 Views
Last Modified: 2013-11-19
Hi All,

I am trying to be a good boy and make sure my pages validate correctly via W3C's XHTML validator but what I have found is that the following control:

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="images/button_logon.png" PostBackUrl="page2.aspx" />

Viewing this within my browser outputs the following code:

<input type="image" name="ctl00$ImageButton1" id="ctl00_ImageButton1" src="images/button_mi_logon.png" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ImageButton1&quot;, &quot;&quot;, false, &quot;&quot;, &quot;page2.aspx&quot;, false, false))" style="border-width:0px;" />

But the W3C validator sees this output html as:

<input type="image" name="ctl00$ImageButton1" id="ctl00_ImageButton1" src="images/button_mi_logon.png" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ImageButton1&quot;, &quot;&quot;, false, &quot;&quot;, &quot;page2.aspx&quot;, false, false))" border="0" />

Has anyone experienced this or have any ways to resolve it?

Many thanks,

Rit
0
Comment
Question by:rito1
[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
  • 2
5 Comments
 
LVL 10

Expert Comment

by:jinn_hnnl
ID: 22820459
What's the problem with this one? Image doesn't show up because the name has been changed? I dont know why you have such out up after rendered.

Can you try to put ~ in the image source to tell compiler to navigate to your root folder?
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/button_logon.png" PostBackUrl="page2.aspx" />

You might wanna try to remove the PostBackUrl (put back later) and put in the OnClick to see if there is any change.

Hope this help

JINN
0
 
LVL 1

Author Comment

by:rito1
ID: 22820505
Hi,

The problem is that .Net is outputting the Image button HTML with the HTML attribute border="0" when the W3C validator is checking it, which is non W3C non-compliant.

Is there any way of stopping asp.net from adding this border attribute and just get it's style from my CSS file?

Thanks,

Rit
0
 
LVL 10

Accepted Solution

by:
jinn_hnnl earned 250 total points
ID: 22820584
Actually this wont make any different when it's rendered to client browser, but if you want to get rid of if. Then set the css for your page:

image, input[type=image]
{
      border:none;
}

however, several IE versions dont support this attributes selector. You can try to set your Image CSSClass Specificly (I always do)

<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/button_logon.png" PostBackUrl="page2.aspx" CssClass="InnerImage"/>

.InnerImage
{
       border:none;
}

Hope this helps

JINN


0
 
LVL 20

Assisted Solution

by:Juan_Barrera
Juan_Barrera earned 250 total points
ID: 22820633
Hi,
Have you tried setting the following web.config property?
<system.web>
<!-- other elements here -->
    <xhtmlConformance mode="Strict" />
</system.web>
This one is to speciffy the renering mode for ASP.NET controls. If set this way, and if your ImageButton IS NOT modified before rendering by any Skin, like you code suggests, then it should validate ok.
For more info, check this link: http://msdn.microsoft.com/en-us/library/ms178159.aspx
 
0
 
LVL 1

Author Closing Comment

by:rito1
ID: 31510660
thank you both
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

739 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