3

i am using asp.net and c# i want to set image height and width property using c# code , i can do it , but the value will be set as an inline style like this :

<img id="image1" style="height:220px;width:800px;border-width:0px;">

but i want something like this

<img id="image1" width="800" height="220">

i use this code , but it render like css code :(

  image1.Width = 800;
  image1.Height =220;

is there any idea?

3 Answers 3

4

Just define it as attribute:

image1.Attributes.Add("width", "800");
image1.Attributes.Add("height", "220");
Sign up to request clarification or add additional context in comments.

1 Comment

It worked for me. Thanks
0

You'll have to use the Unit.Pixel() method. So in your case:

image1.Width = Unit.Pixel(800);
image1.Height = Unit.Pixel(220);

Comments

0

If you use

<asp:Image ID="Image1" runat="server"  Width="800" Height="220" />

instead of

<img id="image1" width="800" height="220">

it should work fine

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.