Wrox Programmer Forums
|
ASP.NET 4.5 General Discussion For ASP.NET 4.5 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4.5 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 30th, 2014, 09:57 AM
Registered User
 
Join Date: Jan 2014
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default <PictureBox>.ImageUrl

I'm trying to get a PictureBox on a web page to show images determined by VB programming in 'Behind Code'. My understanding was that you simply had to set the ImageUrl property of the PictureBox and that would be it. It would appear that I have got that wrong.

Here's the scenario. I have a web page with a number of Picture Boxes thereon, each with the ImageUrl property set to identify an image file, this works fine. But I want to change the images at run time using Behind Code VB.

Each of the images on the page is accompanied by a small Image Description text box which fills in properly, but I can't get the image itself to appear.

What might I be missing? It thought it would have been as simple as setting the ImageUrl property to point to the image file, just as I do when I'm creating a Windows Form Application using VB. I appreciate that there are and will be slight differences between the two, function names and commands and the like, but I didn't think the basic premise would be so different that I can't see it.

I'm working with Visual Studio 2013 for the Web.
 
Old January 30th, 2014, 04:43 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Andy,

It's probably a good idea to post your code. There's no PictureBox in ASP.NET so it's a bit hard to tell what you're doing, and what's going wrong.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old February 3rd, 2014, 07:44 AM
Registered User
 
Join Date: Jan 2014
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default <PictureBox>.ImageUrl

Hello Imar,

Thank you very much for replying to my communique as promptly as you did. Please accept my apologies for not responding equally as quickly, but I was away from home over the weekend.

In fact, I have actually found the solution to my issue, but I'd like to elaborate a little on my scenario.

I'm using Microsoft Visual Studio Express 2013 for Web, in conjuction with your book, Beginning ASP.NET 4 in C# and VB, to try and teach myself something about web design. To this end, my web site contains 3 or 4 pages of narrative, 1 page of small images(12), and another page kept on for experimental purposes.

The images page is the one I was having problems with. You're correct of course in suggesting there aren't any 'Picture Boxes', as used in Visual Basic(VB), but there are 3 similar objects available which go by the names of Image, ImageButton, and ImageMap. Please forgive me if this sounds a bit like 'Teaching your Grandmother to suck eggs'. I've not looked too closely at the 3rd one, ImageMap, but the other two each contain properties such as ID, Width and Height, and one called ImageUrl. This ImageUrl is the property that contains the reference to the desired image file.

This property can be given a default or initial reference, but it only takes one line of VB code to change that reference to point to another image file: ImageButton1.ImageUrl = MyImageUrl.

ImageButton1 is the ID property value(the name given to the object), and ImageUrl is another of the properties.

MyImageUrl is a string variable which contains the Path to, and the Name of, the image file.

Where I was going wrong is that at the point of execution of this instruction, MyImageUrl contained the full path to the file name, eg. D:\This\That\And\The\Next\Thing\<WebSiteLocationOn Server(WWW)>\On\Down\To\<MyFileName>. I required all this because I needed to carry out a File.Exists(<FileName>) function before I would try to do anything further with such a file.

However, the ImageUrl property doesn't want all that, it only wants that bit of the path that follows on from the WWW level of the path, everything preceeding that, including the WWW bit being replaced by the 'Epsilon' (at least I think that's what it's called) character '~', which, now that I'm beginning to appreciate the web environment, makes sense. So the string value at time of execution would be: ~\On\Down\To\<MyFileName>.

In doing this, I resolved my problem.

My next requirement regarding these image placeholders is to figure out how to get the image sized properly within the placeholders, such that it doesn't get stretched, squashed, or whatever else makes it not look right. In VB, you used a 'SizeMode' property set to Zoom, but I haven't found the appropriate replacement for that yet in this working environment. However, I notice in your book that you include something about creating properties for objects, which may be where I'll find a solution, but I haven't explored that in any great detail yet.

Once again, please forgive me Imar, if I sound as if I'm trying to tell you something you don't know already, but perhaps someone else reading this may appreciate my explanation.

Thank you once again, and may I wish you good fortune with this and any other publications you put forward.

Andy.....
 
Old February 4th, 2014, 01:46 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Andy,

Quote:
MyImageUrl contained the full path to the file name, eg. D:\This\That\And\The\Next\Thing\<WebSiteLocationOn Server(WWW)>\On\Down\To\<MyFileName>.
That will never work. Remember this is the web, and this code runs in the browser, not the server. I don't have that folder on my machine, and this it would never work.

Always use (root) relative path (such as /Images/Something.png) or absolute URLs (like http://somedomain.com/Images/Something.png)

Check out Chapter 7 for more details on navigation and URLs.

Quote:
by the 'Epsilon' (at least I think that's what it's called) character '~',
It's called the tilde

Quote:
In VB, you used a 'SizeMode' property set to Zoom, but I haven't found the appropriate replacement for that yet in this working environment
You have a few options:

1. Just set either the height or the width and the browser will scale appropriately.

2. Resize the images server site. This requires more work (Google knows more: https://www.google.com/#q=.NET+resize+images) but gives you more control.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 8: <asp:image> inside <a> & ext.CSS (pg. 274) epc BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 July 12th, 2008 04:37 AM
<style> tags in a <body> vs. <div> bcat BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 1 March 27th, 2005 08:50 AM
<marquee><b>About CHAT App. in PHP4</b></marquee> Ramkrishna PHP How-To 1 September 11th, 2004 07:01 AM
<STRONG> vs <B> and <EM> vs <I> anshul HTML Code Clinic 12 September 1st, 2004 05:22 PM
<<ASP.NET Security>>,download files in chapter 8 alaix All Other Wrox Books 1 July 24th, 2003 10:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.