sagar Bhosale

sagar Bhosale

  • NA
  • 179
  • 175.7k

Can i used Session value two time in single page?

Jul 22 2011 6:59 AM
hi friends ,
can i use session value two times becouse at sexond time when i used session i get null value
plz help me

my code is
protected void Page_Load(object sender, EventArgs e)
  {

  if (!IsPostBack)
  {
  //imgExport.Visible = false;
  string ID = Request.QueryString["0"];
  txtqueryexec.Text = "";
  string LoginId = Convert.ToString(Session["LoginID"]);
  if (LoginId !="")
  {
 
  FillGrid();
  }
 

  }

  Session["DrdQury"] = drpdwn_query.SelectedItem.Text.ToString(); 
  Session["TxtQuery"] = txtqueryexec.Text.Trim();
 
 
  }
  protected void btnexec_Click(object sender, EventArgs e)
  {

  }
  private void FillGrid()
  {
  DataSet ds;
 
  string drd = Convert.ToString(Session["DrdQury"]);  //my first session
  string txt = Convert.ToString(Session["TxtQuery"]);

  if (!String.IsNullOrEmpty(Convert.ToString(Session["DrdQury"])) && !String.IsNullOrEmpty(Convert.ToString(Session["TxtQuery"])))
  {
  ds = objclient.get_queryexec(drd, txt);
  //Session["DrdQury"] = "null"; Session["TxtQuery"] = "null";

  }
  else
  {
  ds = objclient.get_queryexec(drpdwn_query.SelectedItem.Text, txtqueryexec.Text);
  }

  if (ds.Tables[0].Rows.Count > 0)
  {
  gv_command.Visible = true;
  gv_command.DataSource = ds;
  gv_command.DataBind();
  }

  }
  protected void drpdwn_query_SelectedIndexChanged(object sender, EventArgs e)
  {
 
  string query = drpdwn_query.SelectedItem.Text;
  switch(query)
  {
  case "SELECT":
  txtqueryexec.Text = "SELECT * FROM  [TABLENAME]";
  break;

  case "INSERT":
  txtqueryexec.Text = "INSERT INTO  [TABLENAME]  [(col1, col2, col3,...colN)]  VALUES  (value1, value2, value3,...valueN)";
  break;

  case "UPDATE":
  txtqueryexec.Text = "UPDATE  [TABLENAME]  SET column_1 = [value1], column_2 = [value2]";
  break;
  }
  }

  protected void imgExport_Click(object sender, ImageClickEventArgs e)
  {
  string strPath = Server.MapPath(Request.ApplicationPath);
  strPath = strPath + "\\ExportedFiles\\SchemeRating.xls";

  string drd = Convert.ToString(Session["DrdQury"]);  //my second session but here i got null value
  string txt = Convert.ToString(Session["TxtQuery"]);

  DataSet ds = objclient.get_queryexec(drd, txt);

  exportToExcelSlow(ds.Tables[0], strPath);

  Response.Clear();
  Response.Buffer = true;
  Response.Charset = "";
  Response.ClearContent();
  Response.ContentType = "application/ms-excel";
  Response.AddHeader("content-disposition", "attachment; filename=SchemeRating.xls");
  Response.WriteFile(strPath);
  Response.End();
  Response.Flush();
  }

Answers (11)