Click here to Skip to main content
15,941,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
//storing values
 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");
    }
}

// calling like this
 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();
        //panel1
        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();

        //panel2
        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();

        //panel3
        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
Posted
Updated 30-May-13 18:30pm
v5
Comments
Could not get the problem. Please explain here again.
Swayam231 29-May-13 14:38pm    
well the problem is that session is storing the url and the data of the first three images that are displayed 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..
But you have not given the btn4 click event ?
Swayam231 29-May-13 14:42pm    
it is just changing the images like this
image1.imageurl="handler.aspx?pid=4"
image2.imageurl="handler.aspx?pid=5"
image3.imageurl="handler.aspx?pid=6"
Can you debug and see if new images are coming or not by this handlers ?

1 solution

A special thanks to Sunasara Imdadhusen

Here what was lacking in my page_load
void page_load()
{
if(!ispostback)
{
//code
}


it works fine now

:)
 
Share this answer
 
Comments
Sunasara Imdadhusen 31-May-13 0:27am    
Thank you for your appreciations. but make sure do not post code in comment box instead of updating your question!
Swayam231 31-May-13 2:55am    
okk. thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900