Creating inline HTML

D

Dave Keen

Hi

I am a relative newcomer and as usual I am stuck. My ASP.Net 2003 app
has a page which shows data from a database plus an associated picture.
I use an ASP image control sized to 300x300px. All the images are
already the right size - ie maximum 300px, but this control stretches
the (usually non-square) image to fit the 300x300 area, and I don't
want distorted images.
From scouring the net it seems the answer is to create an HTML <IMG>
tag, but while I can format that string, how do I get that into the
HTML for my page dynamically?

Apologies if this is a basic issue but I can't find any clues anywhere
and really appreciate any pointers.

Cheers

Dave
 
D

Dave Keen

Hi Scott

Thanks for your post. I tried that, but couldn't work out how to
convert an integer value to the required format, which is
system.web.ui.webcontrols.unit. Sorry to be a pain but how is that
done?

Cheers

Dave
 
A

addup

Dave said:
Hi

I am a relative newcomer and as usual I am stuck. My ASP.Net 2003 app
has a page which shows data from a database plus an associated picture.
I use an ASP image control sized to 300x300px. All the images are
already the right size - ie maximum 300px, but this control stretches
the (usually non-square) image to fit the 300x300 area, and I don't
want distorted images.

tag, but while I can format that string, how do I get that into the
HTML for my page dynamically?

Apologies if this is a basic issue but I can't find any clues anywhere
and really appreciate any pointers.

Cheers

Dave

Surprise! Your <ASP:IMAGE> actually renders as an HTML <IMG> tag.
So a part of the answer you found has already been implemented.

The question now becomes: How do i force my images to 300px wide
(stretch/compress as required) , preserving the aspect ratio?

A little experimentation reveals that the ASP:IMAGE control is smarter
that it looks. Leave the width attribute(300px) and drop the Height
attribute. The control will figure out the reset.


Having said that, you can always modify the control properties in code
(where I presume you know the dimentions of your image)

example
imgX.Width = New WebControls.Unit(300, UnitType.Pixel)
imgX.Height = New WebControls.Unit(100, UnitType.Pixel)

Where imgX was defined as
<ASP:IMAGE Runat="server" Width="300" ID="imgX" ...


Hope this helps

-- addup --
PS: Just as a matter of curiosity: How are you getting your image from
the DB into the image control?
 
D

Dave Keen

Hi

Thanks for this. I don't know which dimension will be less than 300 in
advance, so although your HTML method works well I can't use it in this
case.

The converting/resizing works a treat. You are a lifesaver.

To answer your point, I am not storing my image in the DB, but in a
folder on the server. The record ID is used to decide the name of the
image. I was wondering whether it was better to do it this way or
experiment with holding pictures in the table (I am using SQL Server).
What do you recommend?

Cheers

Dave
 
S

Scott M.

You don't need to convert anything. Just set the width or height property
of the ASP:IMAGE control at design time.

<ASP:IMAGE ID="blah" WIDTH="300px" IMGURL="blah" />
 
S

Scott M.

Holding the images in the table or as files is simply a design choice. You
can save some (not too much) hard drive space by storing them in the
database. But implementing this is more work to set up.
 
D

Dave Keen

Hi Scott

Thanks for this. I don't think space is a major issue so I will keep
with the separate files for now as I already have that working.

Cheers

Dave
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top