Solved

W3C Validating an ASP.NET ImageButton control

Posted on 2008-10-28
5
854 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
  • 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
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 the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

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

20 Experts available now in Live!

Get 1:1 Help Now