ASP.NET force image size in image control

Hi Experts, is there a way to force the size of an image? I have an image control with dimensions (200px x 100px) set but when I load a bigger (dimensions e.g. 350px x 100px) image into it - it extends.
LVL 1
takwirirarIT Projects ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Russ SuterCommented:
You could add css style properties (or a css class) to the image control. The ASPX markup and css class might look like this:

<asp:Image ID="myImage" runat="server" CssClass="constrained" ImageUrl="~/images/myImage.gif" />

img.constrained
{
  width: auto;
  height: auto;
  max-width: 200px;
  max-height: 100px;
}

Open in new window

0
takwirirarIT Projects ManagerAuthor Commented:
Thanks Russ! That seems to be working fine in the browser but Outlook is. See attached image. Any ideas why?
Outlook v Browser
0
Russ SuterCommented:
If you're going the css route you'd need to embed the css into the document. Even then Outlook might ignore it. You can try adding the style directly in your codebehind.

  myImage.Attributes.Add("style", "width: auto; height: auto; max-width: 200px; max-height: 100px;");

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
takwirirarIT Projects ManagerAuthor Commented:
I tried the code behind but its still looking the same
0
Russ SuterCommented:
They style is valid, it's just being ignored by Outlook.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.