473,769 Members | 6,499 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

objImage.Height .Value
Jun 27 '08 #1
2 2533
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.Webco ntrols.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.ImageU rl = 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.Heigh t.Value);
objImage.Height = Convert.ToInt32 (imgHeight * 0.10);
// scale the height

"Jduan" <Jd***@discussi ons.microsoft.c omwrote in message
news:38******** *************** ***********@mic rosoft.com...
objImage.Height .Value
Jun 27 '08 #2
System.Web.UI.W ebControls.Imag e 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.W ebControls.Imag e objImage = new
System.Web.UI.W ebControls.Imag e();
objImage.ImageU rl = "......"; // put image url here

// set the size of the image control
using (System.Drawing .Image img =
System.Drawing. Image.FromFile( Server.MapPath( objImage.ImageU rl)))
{
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
6407
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 to happen we had to change the context in which asp.net runs from machine to SYSTEM by modifying the machine.config file. Under Windows 2003 no matter how asp.net is set to run as either machine or system. I get the following error: ...
10
1791
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 the code. Exception Details: System.InvalidCastException: Specified cast is not valid. Line 176. Source Error:
9
2153
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 of control names (TextBox, DropDownList, Calendar). On Post back of this drop-down control, I clear a panel control (I have on the same page) of all its controls, then dymamically add the selected control to the panel. For example, if in ddl
0
2350
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). The button work fine when I run it at my local machine. However, when I moved all the programs over to the server, I am unable to view the attachment, although I have the file physically at the server. The error message that I got is: ...
9
6405
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 = CType(e.Item.FindControl("edit_name"), TextBox)
2
2094
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 value As Object) lblCaption.Text = value
1
3110
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 'System.Web.UI.WebControls.SqlDataSource' to type 'System.Collections.IEnumerable'" on line: PageDataSource.DataSource = SqlDataSource2 Thanks for help
1
11387
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 perform edit . when i click update button It display a error message like this...... Unable to cast object of type 'System.Web.UI.WebControls.DataControlLinkButton' to type 'System.Web.UI.WebControls.TextBox'.
2
2363
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
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.