displaying images
I added a photo link to my site. Need a simple way of displaying the images. Preferable "previous" and "next" buttons or so.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pierre DavisPosted Jun 22, 2009, 4:57 PM
<tr valign="top">
<td valign="top">
<img src ="Session["images/Jen and I again new.JPG"].ToString()" border="0" width ="500" height="300px" alt=""/>td>
tr>
Should i have something in Session["LogoFilePath"]
it underlined the Session["images/Jen and I again new.JPG"] as the error.
Alo check previous and next code
public string CounterValue = "1";
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnPrevious_Click(object sender, EventArgs e)
{
if (Session["CounterValue"] !="")
{
Session["CounterValue"] = Convert.ToString(Convert. ToInt32 (Session["CounterValue"])-1);
if (Session["CounterValue"] !="0")
{
if (Session["CounterValue"] =="1")
{
Session["LogoFilePath"] = "images/Alberta&JenHouston.JPG";
}
if (Session["CounterValue"] =="2")
{
Session["LogoFilePath"] = "images/Auntie Stephanie & other Aunt.JPG";
}
if (Session["CounterValue"] =="3")
{
Session["LogoFilePath"] = "images/Jen & friends.JPG";
}
}
else
{
Session["LogoFilePath"] ="images/Pierre Alberta & Mom.JPG" ;
Session["CounterValue"] = "1";
}
}
else
{
Session["LogoFilePath"] ="images/Pierre Alberta & Mom.JPG" ;
Session["CounterValue"] = CounterValue;
}
}
protected void btnNext_Click(object sender, EventArgs e)
{
if (Session["CounterValue"] !="")
{
Session["CounterValue"] = Convert.ToString(Convert. ToInt32 (Session["CounterValue"])+1);
if (Session["CounterValue"] !="0")
{
if (Session["CounterValue"] =="1")
{
Session["LogoFilePath"] = "images/Alberta&JenHouston.JPG";
}
if (Session["CounterValue"] =="2")
{
Session["LogoFilePath"] = "images/Auntie Stephanie & other Aunt.JPG";
}
if (Session["CounterValue"] =="3")
{
Session["LogoFilePath"] = "images/Jen & friends.JPG";
}
}
else
{
Session["LogoFilePath"] ="images/Pierre Alberta & Mom.JPG" ;
Session["CounterValue"] = "1";
}
}
else
{
Session["LogoFilePath"] ="images/Pierre Alberta & Mom.JPG" ;
Session["CounterValue"] = CounterValue;
}
}
}
Pierre DavisPosted Jun 24, 2009, 7:02 PM
Niradhip ChakrabortyPosted Jun 24, 2009, 1:09 AM
You can draw a toolbox and also can do it.
Inside
You need to change the following Code
img src ="<%=Session["LogoFilePath"].ToString()%>" border="30" height="97px" alt=""/>
Revised code:
<img src ="<%=Session["LogoFilePath"].ToString()%>" border="30" height="97px" alt=""/>
Note: as the starting tag of image is missing, the color is changed inside html code.
For session you need to map proper url. Check my last post.
Just for example say your photo.aspx and image folder is in same level, then you can map the image url as "images/Alberta&JenHouston.JPG"(as you are doing it) but
say you have a 'content' folder inside your application and your photo.aspx page is inside your 'content' folder and your 'content' folder and image folder both are in same level. Then inside photo.aspx page you need to map url like this
"../images/Alberta&JenHouston.JPG"
Pierre DavisPosted Jun 23, 2009, 2:57 PM
Here is my HTML code. Please verify that i made the correct changes and that things are in the right places. One thing is that i'm not seeing a photo space in the design view. Should i drag an "image" from the tool box. Also too when i execute the program, this is what show up instead of the image (img src ="<%=Session["LogoFilePath"].ToString()%>" border="30" height="97px" alt=""/>td> . It also causes my page to look different. messes up with the formatting.
On the source code (btnprevious and btnnext), when i run the program, it underlines if (Session with green and says "possible unintended reference comparison; to get a value comparison, cast the left had side to typr"string"
HTML Code
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Photos.aspx.cs" Inherits="Photos" %>
<asp:Content ID="Content2" ContentPlaceHolderID="bodyTitleContentPlaceHolder" Runat="Server">
Photos
asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="bodyContentPlaceHolder" Runat="Server">
Photo Content goes here..<h3>
<asp:Button ID="btnPrevious" runat="server" onclick="btnPrevious_Click"
Text="<< Previous" Width="79px" />
<asp:Button ID="btnNext" runat="server" onclick="btnNext_Click"
Text="Next >>" />
<tr valign="top">
<td valign="top">
img src ="<%=Session["LogoFilePath"].ToString()%>" border="30" height="97px" alt=""/>td>
tr>
h3>
<p>
p>
<br />
asp:Content>
Source Code
public string CounterValue = "1";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Session["LogoFilePath"] = "images/Alberta&JenHouston.JPG";
}
}
protected void btnPrevious_Click(object sender, EventArgs e)
{
if (Session["CounterValue"] !="")
{
Session["CounterValue"] = Convert.ToString(Convert. ToInt32 (Session["CounterValue"])-1);
if (Session["CounterValue"] !="0")
{
if (Session["CounterValue"] =="1")
{
Session["LogoFilePath"] = "images/Alberta&JenHouston.JPG";
}
if (Session["CounterValue"] =="2")
{
Session["LogoFilePath"] = "images/Auntie Stephanie & other Aunt.JPG";
}
if (Session["CounterValue"] =="3")
{
Session["LogoFilePath"] = "images/Jen & friends.JPG";
}
}
else
{
Session["LogoFilePath"] ="images/Pierre Alberta & Mom.JPG" ;
Session["CounterValue"] = "1";
}
}
else
{
Session["LogoFilePath"] ="images/Pierre Alberta & Mom.JPG" ;
Session["CounterValue"] = CounterValue;
}
}
protected void btnNext_Click(object sender, EventArgs e)
{
if (Session["CounterValue"] !="")
{
Session["CounterValue"] = Convert.ToString(Convert. ToInt32 (Session["CounterValue"])+1);
if (Session["CounterValue"] !="0")
{
if (Session["CounterValue"] =="1")
{
Session["LogoFilePath"] = "images/Alberta&JenHouston.JPG";
}
if (Session["CounterValue"] =="2")
{
Session["LogoFilePath"] = "images/Auntie Stephanie & other Aunt.JPG";
}
if (Session["CounterValue"] =="3")
{
Session["LogoFilePath"] = "images/Jen & friends.JPG";
}
}
else
{
Session["LogoFilePath"] ="images/Pierre Alberta & Mom.JPG" ;
Session["CounterValue"] = "1";
}
}
else
{
Session["LogoFilePath"] ="images/Pierre Alberta & Mom.JPG" ;
Session["CounterValue"] = CounterValue;
}
}
}
Niradhip ChakrabortyPosted Jun 23, 2009, 12:57 AM
Please change the following line
and the syntax of assigning session value to inline code is also wrong.It should be inside <%= %> this tag.
so your html code will be
img src ="<%=Session["LogoFilePath"].ToString()%>" border="0" height="97px" alt=""/>
Dont forget to assign some default value to session in page load. Else initially it wont display any image as session is null
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Session["LogoFilePath"] = "images/Alberta&JenHouston.JPG"
}
}
Note: Please give proper image URL. Try to load on image first and then proceed
images/Alberta&JenHouston.JPG indicates you have a folder called image inside your application and image folder is in the same level of your working page.
Niradhip ChakrabortyPosted Jun 22, 2009, 2:06 AM
The below code will work in normal case. Give the proper source,width,height for image
======================================================================
<tr valign="top">
<td valign="top">
<img src="images/body_07.gif" width="646" height="8" alt="">td>
tr>
But as you are using next and previous button. You may need to hold the src path in session variable and pass it accordingly.
Change the code as below:
======================================================================
<tr valign="top">
<td valign="top">
<img src ="<%=Session["LogoFilePath"].ToString()%>" border="0" height="97px" alt=""/>td>
tr>
Now you can have a counter and on each click of next button increase the counter value by one and on each click on previous button deccrease the counter value by one. Initially make the counter value as one.
Hold the counter value in session after each click. And based on the counter value assign the appropriate image to session and display it.
Check the code.
public string CounterValue = "1";
//Previous button code:
protected void btnPrevious_Click(object sender, EventArgs e)
{
If(Session["CounterValue"] !="")
{
Session["CounterValue"] = Convert.ToString(Convert. ToInt32 (Session["CounterValue"])-1);
If(Session["CounterValue"] !="0")
{
If(Session["CounterValue"] =="1")
{
Session["LogoFilePath"] = ="images/image1.gif"
}
If(Session["CounterValue"] =="2")
{
Session["LogoFilePath"] = ="images/image2.gif"
}
If(Session["CounterValue"] =="3")
{
Session["LogoFilePath"] = ="images/image3.gif"
}
}
Else
{
Session["LogoFilePath"] = ="images/image1.gif"
Session["CounterValue"] = "1";
}
}
Else
{
Session["LogoFilePath"] = ="images/image1.gif"
Session["CounterValue"] = CounterValue;
}
}
Same Code will apply for next button only replace the following line
Session["CounterValue"] = Convert.ToString(Convert. ToInt32 (Session["CounterValue"])+1);