What's the server control equivalent of <input type="image"> ?

A

Alan Silver

Hello,

I have a page which I am converting to use themes. The page has an HTML
<input type="image"> element that is used to post to another page. I
would like to replace this with a server control so I can add a skinid.

I tried adding runat="server" and the skinid to the existing control,
but that didn't work. Any other ideas? TIA
 
K

Kevin Spencer

Use a System.Web.UI.HtmlControls.HtmlImage Control.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
A

Alan Silver

Use a System.Web.UI.HtmlControls.HtmlImage Control.

Isn't that just a plain <img> tag? I want an <input type="image"> tag.
Nothing will happen if you click an HtmlImage control (will it?)

Looking at the SDK, it seems that the following should work...

<input type="image" SkinID="imgBasket" runat="server" />

where the skin file contains...

<asp:ImageButton skinid="imgBasket" imageurl="images/basket.gif"
width="119" height="20" runat="server" />

however, that produces the following HTML...

<input name="ctl00$cphMainBody$ctl00$ctl01" type="image" />

As you can see, no src attribute, and no width or height.

Any ideas? Thanks for the reply.
 
K

Kevin Spencer

Hi Alan,

Sorry, yes, the ImageButton is what yuo want, to submit the form. I'm not
sure what is wrong with your use of the "SkinID" attribute. I know that it
is not an HTML attribute, and perhaps ASP.Net checks it. I've never tried to
add a non-standard attribute to an ASP.Net Control. You might try using the
AddAttributes() method of the Control to add it.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
A

Alan Silver

Hi Alan,
Sorry, yes, the ImageButton is what yuo want, to submit the form. I'm not
sure what is wrong with your use of the "SkinID" attribute. I know that it
is not an HTML attribute, and perhaps ASP.Net checks it. I've never tried to
add a non-standard attribute to an ASP.Net Control. You might try using the
AddAttributes() method of the Control to add it.

According to the SDK, SkinID is an attribute of the HTML control, so
should be used by the framework. That's why I'm confused why it didn't
work.

Any ideas? Thanks
 
A

Alan Silver

I would think...an ImageButton. But I haven't tried it...

I have, and I couldn't get it to work, hence my post ;-)

Thanks anyway
 
K

Kevin Spencer

Hi Alan,

Yes, you're right. I have never used this attribute, so I was unfamiliar
with it. I believe your problem can be solved by assigning an ID attribute
to the Control.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
A

Alan Silver

Hi Alan,
Yes, you're right. I have never used this attribute, so I was unfamiliar
with it. I believe your problem can be solved by assigning an ID attribute
to the Control.

Thanks for the reply, however it didn't work ;-)

I changed the server tag to look like...

<input id="inpAddToBasket" type="image" SkinID="imgBasket"
runat="server" />

and this produced the following HTML...

<input name="ctl00$cphMainBody$ctl00$inpAddToBasket" type="image"
id="ctl00_cphMainBody_ctl00_inpAddToBasket" />

As you can see, the src attribute has not been set.

Any other ideas? I'm a bit stuck here as I think I'm doing exactly what
the SDK says you should be able to do, but it isn't working.

Thanks again
 
A

Alan Silver

Hello,

OK, I found the source of my problem...

My skin file contains a definition for an ImageButton, but the control
I'm using *isn't* one of those, it's an <input type="image"> control,
which is an HTML control. ImageButton is a web server control, not an
HTML control.

The problem is that it seems you can't skin HTML controls!! You look in
the SDK, and you see that they have a SkinID property, you look in the
info on skinning and you don't see any disclaimer telling you that you
can't skin an HTML control, but if you try adding the following to your
skin file...

<input type="image" skinid="imgBasket" src="images/basket.gif"
width="119" height="20" runat="server" />

.... you get a parser error "The control type
'System.Web.UI.HtmlControls.HtmlInputImage' cannot be themed" when you
try and run the page.

So either I'm doing something wrong and there's another way of applying
a skin to an HTML control, or there's a hole in the framework
functionality that is emphasised by an apparently useless property
(SkinID).

I would point out that HTML controls also have an EnableTheming
property, which does imply that they can be skinned, but I can't find
out how to do it.

Anyone any idea about this?
 
K

Kevin Spencer

Hi Alan,

Well, thanks to you I've been finding out all about Themes. :)

I have not learned everything, but hopefully enough to keep you going.

HtmlControls all inherit System.Web.UI.Control, which has a SkinID property
and an EnableTheming property. However, not all System.Web.UI.Controls are
themeable. There is an attribute called ThemeableAttribute, which, if set to
false, disables theming for a Control, regardless of these 2 properties.

The difficult part for me is finding out what Controls are themeable and
what Controls are not. You can't view attributes in the .Net SDK. They are
not documented (unfortunately). You can view them in Ildasm.exe, but it's
like looking for a needle in a haystack. I tried using the JungleCreatures
..Net decompiler, but it doesn't support version 2.0. Apparently, an
HtmlInputImage Control is not themeable. I searched the WWW for some sort of
list, but came up empty. It seems for now your only alternative is to do
what you've been doing in order to find out.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
A

Alan Silver

Hi Alan,

Hello
Well, thanks to you I've been finding out all about Themes. :)

Oh well, at least one of us has benefited from this ;-)

Themes are good aren't they?
I have not learned everything, but hopefully enough to keep you going.

Oh well, that makes two of us!!
HtmlControls all inherit System.Web.UI.Control, which has a SkinID property
and an EnableTheming property. However, not all System.Web.UI.Controls are
themeable. There is an attribute called ThemeableAttribute, which, if set to
false, disables theming for a Control, regardless of these 2 properties.

Yeah, but it's true by default, so that's a bit of a red herring.
The difficult part for me is finding out what Controls are themeable and
what Controls are not. You can't view attributes in the .Net SDK. They are
not documented (unfortunately). You can view them in Ildasm.exe, but it's
like looking for a needle in a haystack. I tried using the JungleCreatures
.Net decompiler, but it doesn't support version 2.0. Apparently, an
HtmlInputImage Control is not themeable. I searched the WWW for some sort of
list, but came up empty.

Me too. I can't understand why this isn't documented. Having the
EnableThemeing and SkinID properties implies they can be themed, and I
couldn't find any docs to say otherwise. You don't even get an error,
just a lack of theming. Sounds like an oversight on MS's part if you ask
me. They should have done this a bit better.
It seems for now your only alternative is to do
what you've been doing in order to find out.

At the moment I am contemplating rewriting some code to avoid using the
<input> tag. This feels wrong, but I can't see any other way around it.
Now that 2.0 supports cross-page posting, I should be able to do what I
want with server controls, but that means rewriting, retesting, etc. I
was right on the point of deploying the site as well. Ho hum.

Thanks anyway. If you find out anything more, please report back.
 
K

Kevin Spencer

Hi Alan,

With the advent of aspect-oriented programming, and Microsoft's upcoming
"Windows Communication Foundation" ("Indigo")product, which uses
aspect-oriented programming, and therefore, attributes quite a bit, I think
MS will have to re-examine how they document their .Net classes. If you're
going to make extensive use of attributes, it makes sense to document them,
and how they affect behavior.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
A

Alan Silver

Hi Alan,
With the advent of aspect-oriented programming, and Microsoft's upcoming
"Windows Communication Foundation" ("Indigo")product, which uses
aspect-oriented programming, and therefore, attributes quite a bit, I think
MS will have to re-examine how they document their .Net classes. If you're
going to make extensive use of attributes, it makes sense to document them,
and how they affect behavior.

Unfortunately, my web site can't wait that long!!

It would have been nice if they'd got the documentation clear at this
stage!!

Ta ra
 
J

jpierce

Kevin said:
I tried using the JungleCreatures
.Net decompiler, but it doesn't support version 2.0. Apparently, an
HtmlInputImage Control is not themeable.

Hi Kevin,

We do have a 2.0 version of our Decompiler.NET product available on our
web site that decompiles 2.0 and 1.1 assemblies. Licensed customers can
use their licenses with either the 1.1 and 2.0 versions. We also
provide a free version to MSDN subscribers that decompiles .NET
Framework assemblies 100% in the browser UI. You can download the 2.0
version of the product from the 2.0 link on the products page on our
web site at:
http://www.junglecreatures.com/DesktopDefault.aspx?tabindex=3&tabid=3

Jonathan Pierce
President
Jungle Creatures, Inc.
http://www.junglecreatures.com/
 
K

Kevin Spencer

Thanks Jonathan. I will look into it. You have an excellent product there!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
A

Alan Silver

Apparently, an HtmlInputImage Control is not themeable. I searched the
WWW for some sort of list, but came up empty. It seems for now your
only alternative is to do what you've been doing in order to find out.

ASP.NET is just brilliant!!

I was working on another site his morning, and came across my first need
to do cross-page posting. This was so easy that I'm going to redo the
above-mentioned code with a cross-page post, removing the need for an
HtmlInputImage control. I can just use a normal server control and set
the PostBackUrl property.

Just thought I'd post this up for the benefit of anyone reading this
later. No you can't theme the HtmlInputImage, but it's very possible you
won't need to as cross-page posting is really easy.

I'm still excited about it ;-) Childish really!!

Ta ra
 
K

Kevin Spencer

Good stuff, Alan! I was unaware of this new feature, and looked it up.
Thanks for sharing what you learned!

--

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,177
Latest member
OrderGlucea
Top