can ASP.NET do this?

J

John Salerno

Hi all. I'm new to C# and haven't really used ASP.NET much yet. I'm
wondering if there's a fairly simple way to write a bit of code that
would allow me to insert an image into an html page, for use in multiple
pages, so that if I ever need to change the image I can change just one
file instead of each page.

PHP was suggested to me, something like:

<?php #include file="name.ext"; ?>

OR

<? include $_SERVER['DOCUMENT_ROOT'] . "/images/some_file.jpg"; ?>

but I was wondering if I could do this in ASP.NET also, since I'd like
to sort of stay in the realm of .NET programming right now.

Thanks.
 
H

Hans Kesting

Hi all. I'm new to C# and haven't really used ASP.NET much yet. I'm wondering
if there's a fairly simple way to write a bit of code that would allow me to
insert an image into an html page, for use in multiple pages, so that if I
ever need to change the image I can change just one file instead of each
page.

PHP was suggested to me, something like:

<?php #include file="name.ext"; ?>

OR

<? include $_SERVER['DOCUMENT_ROOT'] . "/images/some_file.jpg"; ?>

but I was wondering if I could do this in ASP.NET also, since I'd like to
sort of stay in the realm of .NET programming right now.

Thanks.

One word of warning: you can't just include the contents of a jpg
file (or any onther image) in the html. This is because of the way
html is defined, not a limitation of asp.net (any other server-side
technology has this "problem").
The only way is to provide an <img> tag with a src property that
points to a location where the file can be found.

Hans Kesting
 
J

Jarod

Hi all. I'm new to C# and haven't really used ASP.NET much yet. I'm
wondering if there's a fairly simple way to write a bit of code that would
allow me to insert an image into an html page, for use in multiple pages,
so that if I ever need to change the image I can change just one file
instead of each page.

So one of possible scenario will be to use UserControl, when you add a new
one to your project it looks almost like a new website than you can add
Image control set up as you wish, and use it UserControl on all your pages.
If you need to change the picture you can change usercontrol a little and
than all pages in your project will work with diffrent image. You can even
you use it control with diffrent pages and projects but than you must copy
your image with it not only a control code.
Jarod
 
E

Edwin Knoppert

Use a class having a constant or function which returns a string.

In the html you could use:

<%=class1.myimage1%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top