Solved

W3C Validating an ASP.NET ImageButton control

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Achieve json result 2 65
asp.net mvc input file 2 32
Word Directory is not in the drop down list 4 25
Turn on intranet settings 1 37
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

910 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

21 Experts available now in Live!

Get 1:1 Help Now