Solved

W3C Validating an ASP.NET ImageButton control

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

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 In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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)

680 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