I must be barking up the wrong tree because I have found nothing in the internet about this. I'd like to know how to achieve a server control that renders something like this...
<button><img src="new.gif" /> New</button>
I can't seem to get anywhere with it though. What gives?
The [url=http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.imagebutton.aspx]asp:ImageButton[/url] control, perhaps? Alternatively you can add an image to a HyperLink using it's [url=http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlink.imageurl.aspx]ImageUrl
property[/url].
If you really want both text [i]and[/i] an image on a button then you'll have to write your own control as it's very non-standard.
I don't understand why it is non-standard. Is it literally not supported by the XHTML standard? I would understand if that was the case. But both Firefox and IE6 render my example perfectly. I realize that doesn't mean it's valid HTML, but it makes me think
that it might be. Am I the only person that wants an image on a button, as well as text, but doesn't want to render the entire representation of it? We've had this in WinForms since .Net 1.0. And it's doable, and maybe valid, in HTML. So why not?
There are a lot of things doable in WinForms that are either not possible or quite difficult to accomplish in WebForms - the web platform - it's basically the nature of the beast, as it is today.
I realize that the web and winforms are totally different. My point is that if it's trivial and doable on winforms, and it has been for a long time, and it's trivial and doable in HTML (standards aside) then shouldn't we have it by now? If it was rocket
science to accomplish, I'd understand, but evidently it isn't.
[quote user="johndehope3"]I realize that the web and winforms are totally different.
I'm not quite sure you do, to be honest, from what you are saying.
My point is that if it's trivial and doable on winforms, and it has been for a long time, and it's trivial and doable in HTML (standards aside) then shouldn't we have it by now?
You can't just say "standards aside" as if that is a minor point. Whether it's doable on winforms is totally irrelevent - Microsoft did not create (X)HTML. The standards for web markup are goverened by [url=http://www.w3.org/]The World Wide Web Consortium[/url].
All Asp .NET controls HAVE to render valid HTML markup otherwise there is no guarantee how a browser will render it now or in the future. You can't just brush standards aside as if they don't matter. The web isn't a single platform running on one operating
system - it encompasses many different browsers, some of which (such as screen readers or mobile browsers may not even render images).
To do what you want to do in ASP .NET you'd need to do something like this:
You could then write a custom server or user control to encapsulate those controls so they only expose the properties you wish to set once, such as the event when clicked.
johndehope3
Member
50 Points
10 Posts
Button With Image And Text
Sep 06, 2006 06:47 PM|LINK
I must be barking up the wrong tree because I have found nothing in the internet about this. I'd like to know how to achieve a server control that renders something like this...
<button><img src="new.gif" /> New</button>
I can't seem to get anywhere with it though. What gives?
ASP.NET form button image
augustwind
All-Star
35874 Points
4902 Posts
ASPInsiders
Moderator
Re: Button With Image And Text
Sep 06, 2006 06:49 PM|LINK
The regular button just shows text - the ImageButton does exactly what the button does, but you can use an image for it's GUI representation.
So, are you saying that you want a button to show an image AND text on the button?
All Things Dot Net
Stored Procs and Code in a Flash!
ASP.Net Sitemap Creator
Connect
Contributor
2304 Points
455 Posts
Re: Button With Image And Text
Sep 06, 2006 06:50 PM|LINK
If you really want both text [i]and[/i] an image on a button then you'll have to write your own control as it's very non-standard.
johndehope3
Member
50 Points
10 Posts
Re: Button With Image And Text
Sep 06, 2006 06:56 PM|LINK
johndehope3
Member
50 Points
10 Posts
Re: Button With Image And Text
Sep 06, 2006 07:00 PM|LINK
augustwind
All-Star
35874 Points
4902 Posts
ASPInsiders
Moderator
Re: Button With Image And Text
Sep 06, 2006 07:06 PM|LINK
All Things Dot Net
Stored Procs and Code in a Flash!
ASP.Net Sitemap Creator
Connect
Contributor
2304 Points
455 Posts
Re: Button With Image And Text
Sep 06, 2006 07:13 PM|LINK
What is the (X)HTML you are using that is rendering? If it's anything like:
<input type="button" text="Button" ><img src="image.gif" /></input>
then that is totally invalid XHTML. The web is competetly different to Windows forms.
johndehope3
Member
50 Points
10 Posts
Re: Button With Image And Text
Sep 06, 2006 07:20 PM|LINK
I realize that the web and winforms are totally different. My point is that if it's trivial and doable on winforms, and it has been for a long time, and it's trivial and doable in HTML (standards aside) then shouldn't we have it by now? If it was rocket science to accomplish, I'd understand, but evidently it isn't.
I was aiming for something like...
<button><img ...> Text</button>
johndehope3
Member
50 Points
10 Posts
Re: Button With Image And Text
Sep 06, 2006 07:30 PM|LINK
According to About.Com the BUTTON tag is valid XHTML and the IMG element is valid within a BUTTON...
http://webdesign.about.com/od/htmltags/p/bltags_button.htm
Connect
Contributor
2304 Points
455 Posts
Re: Button With Image And Text
Sep 06, 2006 07:41 PM|LINK
I'm not quite sure you do, to be honest, from what you are saying.
You can't just say "standards aside" as if that is a minor point. Whether it's doable on winforms is totally irrelevent - Microsoft did not create (X)HTML. The standards for web markup are goverened by [url=http://www.w3.org/]The World Wide Web Consortium[/url]. All Asp .NET controls HAVE to render valid HTML markup otherwise there is no guarantee how a browser will render it now or in the future. You can't just brush standards aside as if they don't matter. The web isn't a single platform running on one operating system - it encompasses many different browsers, some of which (such as screen readers or mobile browsers may not even render images).
To do what you want to do in ASP .NET you'd need to do something like this:
<asp:LinkButton ID="LinkButton1" runat="Server" OnClick="ButtonClick_Event">Text</asp:LinkButton>
<asp:ImageButton ID="ImageButton1" runat="Server" ImageUrl="image.gif" OnClick="ButtonClick_Event"></asp:ImageButton>
You could then write a custom server or user control to encapsulate those controls so they only expose the properties you wish to set once, such as the event when clicked.