Layout of my project:
2 Pages.aspx
4 buttons, bt1, bt2, bt3,bt4
3 image control im1, im2,im3
3 Labels
I am retrieving 6 image from db using handler. When the page loads 3 image along with their name is shown in the page..
page_load
{
image1.imageurl="handler.aspx?pid=0";
image2.imageurl="handler.aspx?pid=1";
image3.imageurl="handler.aspx?pid=2";
}
and
when again a user clicks on bt4 another 3 images loads in the same place replacing the previous data
bt4_click
{
image1.imageurl="handler.aspx?pid=3";
image2.imageurl="handler.aspx?pid=4";
image3.imageurl="handler.aspx?pid=5";
}
Now i want that whenever a user clicks on bt1 (say) the image(im1) along with the name is passed on to another page..
i have written codes like this:
protected void button1_click(object sender, EventArgs e)
{
Session["img"] = Image1.ImageUrl;
Session["bk1"] = Label1.Text;
Response.Redirect("Details.aspx");
}
protected void button2_click(object sender, EventArgs e)
{
Session["img"] = Image2.ImageUrl;
Session["bk1"] = Label2.Text;
Response.Redirect("Details.aspx");
}
protected void button3_click(object sender, EventArgs e)
{
Session["img"] = Image3.ImageUrl;
Session["bk1"] = Label3.Text;
Response.Redirect("Details.aspx");
}
}
if (Session["img"] != null && Session["bk1"] != null)
{
Image1.ImageUrl = Session["img"].ToString();
TextBox1.Text = Session["bk1"].ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
string strConn = "Data Source=SWAYAM;Initial Catalog=Swayam;Integrated Security=SSPI; ";
SqlConnection con = new SqlConnection(strConn);
con.Open();
string st = "select top 1 name,author,price from image4 order by Row_id desc";
SqlCommand cmd = new SqlCommand(st, con);
SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
string name = "";
string author = "";
string price = "";
if (sdr.Read())
{
name = sdr["name"].ToString();
author = sdr["author"].ToString();
price = sdr["price"].ToString();
}
sdr.Close();
con.Close();
SqlConnection con2 = new SqlConnection(strConn);
con2.Open();
string st2="Select name, author, price from image4 where Row_id=(select max(Row_id)-1 from image4)";
SqlCommand cmd2 = new SqlCommand(st2, con2);
SqlDataReader sdr2 = cmd2.ExecuteReader(CommandBehavior.CloseConnection);
string name2="";
string author2="";
string price2="";
if (sdr2.Read())
{
name2 = sdr2["name"].ToString();
author2 = sdr2["author"].ToString();
price2 = sdr2["price"].ToString();
}
sdr2.Close();
con2.Close();
SqlConnection con3 = new SqlConnection(strConn);
con3.Open();
string st3 = "Select name, author, price from image4 where Row_id=(select max(Row_id)-2 from image4)";
SqlCommand cmd3 = new SqlCommand(st3, con3);
SqlDataReader sdr3 = cmd3.ExecuteReader(CommandBehavior.CloseConnection);
string name3 = "";
string author3 = "";
string price3 = "";
if (sdr3.Read())
{
name3 = sdr3["name"].ToString();
author3 = sdr3["author"].ToString();
price3 = sdr3["price"].ToString();
}
sdr3.Close();
con3.Close();
Label1.Text = name;
Label2.Text = author;
Label3.Text = "Rs."+ price;
Label4.Text = name2;
Label5.Text = author2;
Label6.Text = "Rs."+ price2;
Label7.Text = name3;
Label8.Text = author3;
Label9.Text = "Rs."+ price3;
Image1.ImageUrl="~/Image handler.ashx?pid=0";
Image2.ImageUrl = "~/Image handler.ashx?pid=1";
Image3.ImageUrl = "~/Image handler.ashx?pid=2";
}
My problem here is that session is only carrying the values of the first three images and labels not the new data which is loaded by bt4_click???
The problem is that session is storing the imageurl and the data of the first three images that are displayed on page load...
but when the images are changed due to bt4_click the stored data of first three images is passed on. not of the new ones..
any suggestions or help is appreciated