473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

RE: Unable to cast object of type 'System.Web.UI.WebControls.Unit' to

objImage.Height.Value
Jun 27 '08 #1
2 2500
Thanks so much for your reply... However, I tried it and I still can't make
it work. Instead of returning the Width or the Height is simply returns a
0. I also notice that when I hover the .Value in the selection box that
displays when I am typing the command... ie objImage.Height.Value it
describes Value as "Getting the length of the System.UI.Webcontrols.Unit".

I have included the code that I generated based on your response to my
question. As a newbie it may be that I don't understand exactly how to use
it. Further direction would be helpful.

Code Snippet..

// create new Image() object for each Photo
Image objImage = new Image();

objImage.ImageUrl = strWebPath + "/" +
objPhoto.Name;

int imgWidth =
Convert.ToInt32(objImage.Width.Value);
objImage.Width = Convert.ToInt32(imgWidth * 0.10);
// scale the width

int imgHeight =
Convert.ToInt32(objImage.Height.Value);
objImage.Height = Convert.ToInt32(imgHeight * 0.10);
// scale the height

"Jduan" <Jd***@discussions.microsoft.comwrote in message
news:38**********************************@microsof t.com...
objImage.Height.Value
Jun 27 '08 #2
System.Web.UI.WebControls.Image is just a ASP.NET server-side control used to
render an image. It does not actually load the image on the server,
therefore, by default, objImage.Height.IsEmpty is always true and the
objImage.Height.Value is 0.

There are a lot of ways to get the actual image size on the server side, all
of them will involve reading the actual image file. The simplest way would be
like this:

// create image web control and set the image Url
System.Web.UI.WebControls.Image objImage = new
System.Web.UI.WebControls.Image();
objImage.ImageUrl = "......"; // put image url here

// set the size of the image control
using (System.Drawing.Image img =
System.Drawing.Image.FromFile(Server.MapPath(objIm age.ImageUrl)))
{
objImage.Width = new Unit(img.Width * 0.1);
objImage.Height = new Unit(img.Height * 0.1);
}
Hope this works.

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Carlos G Benevides | last post by:
I have a ASP.Net web application that has two assemblies that run under com+. Under Windows 2000 the two assemblies are added to com+ automatically when instantiated from the web site. For this...
10
by: Arjen | last post by:
Hello, Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in...
9
by: Matt Tapia | last post by:
I having a problem that receives the following error: Specified cast is not valid And I need some help. Here is what is happening: I have a form with a drop-down control that contains a list...
0
by: Seok Bee | last post by:
Dear Experts, In my web application, I'm having a button to view an attachment. After I retrieve the record from database (Ms. Access), I have a button to view the attachment (if there is any)....
9
by: Jim in Arizona | last post by:
I get this error: Unable to cast object of type 'System.Web.UI.HtmlControls.HtmlInputText' to type 'System.Web.UI.WebControls.TextBox'. Using this code: Dim test3 As TextBox test3 =...
2
by: rn5a | last post by:
Suppose I have this property in a user control (which is named Address.ascx): <script runat="server"> Public Property Caption() As Object Get Caption = lblCaption.Text End Get Set(ByVal...
1
by: Chris | last post by:
Hi, I want to limit the amount of data shown in a page coming from a database. Everything works except that I get the error: "Unable to cast object of type...
1
by: sana krishna | last post by:
Hai, Pls anyone help me........................... I am using ASP.NET(C#). I want to display the data in a gridview and make the gridview to become editable and insert and delete. But i can't...
2
by: Andy B | last post by:
I have the following listView control on a page: <asp:ListView ID="ListView1" runat="server" ItemPlaceholderID="PlaceHolder1"> <ItemTemplate> <dl> <dt>
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.