.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Change dimensions of image if width exceeds certain amount

Posted By:      Posted Date: September 24, 2010    Points: 0   Category :ASP.Net

(In a different post  I asked about how to access an Image control held in a FormView template. This topic has been mixed into it, so I thought I would start a fresh post only about this problem.)

I would like to perform a simple check to ascertain the width of an image. If it exceeds a certain dimension I would like to give the image a width property. I understand this doesn't not affect file size, just dimensions, but it is for presentation purposes. I'm still learning VB, but the code below is what I have tried so far:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim LargeImage As Image = DirectCast(FormView1.FindControl("Image1"), Image)

        Dim Width As Integer
        Width = LargeImage.Width.Value

        If Width > 560 Then
            LargeImage.Width = Unit.Pixel(560)
        End If

    End Sub


Thanks in advance,


View Complete Post

More Related Resource Links

change image button image


i am making a web form with a VB code behind.  on the form I have a down arrow imageButton that when pressed hides certain data.  what i want to do is change the button to an up arrow and vice versa whenever pressed.  i have both images loaded onto my project already.  any suggestions.

thank you

change css and image url

HiI have a masterpage on a site, in order to use the site the user has to login first. And after that I  would like to customize the masterpage with a unique css file and a unique imageurl for a image on the masterpage. Whar is the preferable way to achive this?

Use update progress control to change image control imageurl

UPDATE: Apologies for the previous formatting error - hopefully the post is now more readable... Hi I have a button with an image control next to it. Before the button is clicked, the image control "ConfirmedStatusImage" shows a "cancel.png" image. When the button has been clicked (and some other code successfully executed), then I change the imageurl for the "theConfirmedStatusImage" to show a "ok.png" image. Quite a bit of time can often pass between clicking the button and the associated code executing, so I have an ajax update progress control that shows a "bluespinner.gif" image while the page is updating after the button click. At the moment, the update progress updating image appears next to the "ConfirmedStatusImage" control. However, I would like to change things so that when the update progress starts, the imageurl of "ConfirmedStatusImage" changes from "cancel.png" to the update progress image (i.e., the "bluespinner.gif"). Then, when the update is complete, then the image should change to the "ok.png" image. My question is: how can I achieve this? As far as I can tell, the update progress control does not have any events that I can hook into. Also, placing the "ConfirmedStatusImage" inside the ProgressTemplate would not work either, as this only displays

Change image button image on hover

Hoep this si simple I would like to change the image in an image button when the user hovers over it ..can anyone helpThanks  

Change image when mouse over!

I want to know that how can I change an image when mouse over image?!?!   thanks.

How to change the size (width) of scorecard columns in Dashboard Designer?

Is there any way to change the size (width) of scorecard columns in Dashboard Designer?

How to change a Left Navigation width in sharepoint

Hello,   Any body help me out how to change or modify the width of left navigation..   thank you  

Change image paths programmatically



I am working on a localization project, some of the localized text are in graphics, some of the example graphics  paths:




My web forms use <asp:image> controls and <img> tags (runat = sever) to point to graphics in /en/images. I need to a function to loop through all image control and point them to different paths based on the locale set at runt time. Which event should I override and how do I write it?

All my web pages inherit from a base page, I don't know if that makes differences.




Detect Width and Height of .jpg image



I have an image on this path that I first check if it exists. If it exists I wonder what the method is to get width and height of this image ?

            if (File.Exists(Server.MapPath("Images\\Pic1.JPG")))
		    //How to get the Width and Height of this JPG Image ?


Auto resize image width only


I have a question regarding the resizing of images.

My problem is that I would like to resize files that are being uploaded automatically. But I only want to resize the width.

Regarding the height of the file, this should auto adjust it self. Forexample; If I'm uploading a file that is 1000 px in width and 2000px in height and then resize it to 500px in width, then I want the height to be auto resized to 1000px. In other words the height and width has to be proportional. 

Could someone help me out on this. 

Thanks for reading. 

Change form width ???


With this code I can change the width of a panel til the width of the form - the useable part of the form !

  public partial class Form1 : Form
    public Form1()

    private void Form1_Load(object sender, EventArgs e)
      Panel aPanel = new Panel();
      aPanel.BorderStyle = BorderStyle.FixedSingle;
      aPanel.Width = ClientSize.Width;

How can I do it the other way around = set the form width to the width of a panel ?

It seems like the ClientSize.Width is READ ONLY !

I can use

this.Width = aPanel.Width + 8;

but what is this spooky 8 ????


Best regards KSor, Denmark

Change image in gridview after binding


I have a need to change the image (bound) in a gridview after it has been databound.  Basically i need to assign a photo to a record and I want to change the image url for that row.  I can change the text in any of the cells of the row but I can't seem to find property for the imageurl.

This is what I do to change the text(cell 5).

int index = int.Parse(Session["NSI"].ToString());

GridViewRow row1 = GridView1.Rows[index];
row1.Cells[5].Text = "just some text";

But now I need to change the image url for cell 0

something along the lines of ...

row1.Cells[0].ImageUrl = "~images\photos\12345.jpg";

How do I get to that property?

Thank you.

Change Site.Master width in CSS


Hi, I'm all new to ASP.NET but not to CSS/HTML.

I created a new WebApplication in Visual Studio 2010. In the CSS document (Site.css) it says:

    width: 960px;
    background-color: #fff;
    margin: 20px auto 0px auto;
    border: 1px solid #496077;

And the first div tag in the Site.Master file is:

<div class="page">

If I change that 960px to 400px for instance, it does not change the width of my document. Even if I write 0px it does not "recognize" the change.


Change background when "new" image is visible



I would like to change the background-color in my XSLTListView, when the ms-newgif is visible in a row.

How can I check in XSLT if the image is vivisble ?



How to change wpf image source on runtime ?


I get new bitmap from some other component ( dont have any control on the other component ) every 5 seconds and i need to update my wpf image control with the new bitmap ( every 5 seconds ... ).


[ i cant save the bitmap to the disk and then load it as file ]

I cant find any way to update this wpf image control in run-time.

How can i do it ?


dynamically change the background image of a


I have created an asp.net website using visual studio express 2008.  I am having trouble mapping a path to my image folder from other files in the website.

My image folder's path is http://localhost/Cafeteria/Image/MyImage.gif

My aspx page that I want to map from is http://localhost/Cafeteria/Submeals/burgers.aspx

In my /burgers.aspx I have the following code:


<asp:content id="Content1" contentplaceholderid="Main" runat="server"><

Image Color Change Dynamically on the fly, is it possible?


Hey All,

I have created an aspx page that is displaying user profiles, and on that page I have an asp.net image control that I dynamically populate at runtime based on the users profile image.

I have created several themes, just modifying css to display the profiles with different background and different layouts.

For fun I have created one theme that is kind of like the matrix, and I would like to be able to take the users profile image and change it to a 'green scale' so to speak, or even just a straight up green color, more so this one #20f380. The profile images are just jpg, and are already cartoonish so they should change to green without the image looking to bad.

Is there a way to use code behind to change an image's colors?

C# or VB is fine, currently I've not been able to find any tutorials that work for me, or are close to what I am trying to do.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend