Loading ...

passing parameters between pages

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  getting started / general asp.net   » passing parameters between pages

passing parameters between pages

Posts under the topic: passing parameters between pages

Posted: 12/3/2011

Lurker 5  points  Lurker
  • Joined on: 12/3/2011
  • Posts: 1

hi 

i have a problem in my code, i am trying to read records from database and beside each record i want to place a button  which redirecting me to another page , i want this button to send also the id of the record besides it but the problem is that it sends the id of the last record always.

here is the code 

if (!Page.IsPostBack)
{

string connectionString = WebConfigurationManager.ConnectionStrings["mokattam"].ConnectionString;
SqlConnection con = new SqlConnection(connectionString);


try
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT subject, body, id FROM complains", con);
cmd.ExecuteScalar();
SqlDataReader dr = cmd.ExecuteReader();
int i = 0;



while (dr.Read()){

AccordionPane ap = new AccordionPane();
Button b = new Button();
ap.ID = "ap" + i;
b.ID = "b" + i;
b.Text = "Reply";
string url = "reply.aspx?id=" + Session["id"];
b.PostBackUrl = url;
ap.HeaderContainer.Controls.Add(new LiteralControl(dr["subject"].ToString()));
ap.ContentContainer.Controls.Add(new LiteralControl(dr["body"].ToString()));
ap.ContentContainer.Controls.Add(new LiteralControl("</br>"));
ap.ContentContainer.Controls.Add(b);

Accordion1.Panes.Add(ap);
i++;

}


dr.Close();





}
catch (Exception err)
{
Response.Write(err.Message);
}
finally
{

con.Close();


}
}
}

Posted: 1/10/2012

Professional 8338  points  Professional
  • Joined on: 4/15/2009
  • Posts: 424

where did you assign the value for your session?


Posted: 2/20/2012

Lurker 10  points  Lurker
  • Joined on: 2/20/2012
  • Posts: 2
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Response.Redirect("DesiredPage.aspx?id=" + Session("UserID"))
    End Sub

 


Posted: 3/19/2012

Lurker 82  points  Lurker
  • Joined on: 9/15/2009
  • Posts: 9

Why u r not using

string url = "reply.aspx?id=" + dr["id"].ToString();

instead of

string url = "reply.aspx?id=" + Session["id"];


I think It will work as u need.


Page 1 of 1 (4 items)