473,756 Members | 3,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 2531
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
1790
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
6404
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
3109
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
11386
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
2362
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
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10032
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...
1
9841
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
6534
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
5141
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
5303
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
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
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.