I am trying to pass a vbscript session variable to my c# page.
Upon research I found this page:
Transfer Session Variables from Classic ASP to ASP.NET
I don’t know how to change my
Int32 intresortID = Convert.ToInt32(Request.QueryString["TypeID"]);
to read in the session variable in the same manner as from the code provided in the link above(pasted below:)
<TITLE>ASPNETPage1.aspx</TITLE>
<%@ Page language="c#" %>
<script runat=server>
// We iterate through the Form collection and assign the names and values
// to ASP.NET session variables! We have another Session Variable, "DestPage"
// that tells us where to go after taking care of our business...
private void Page_Load(object sender, System.EventArgs e)
{
for(int i=0;i<Request.Form.Count;i++)
{
Session[Request.Form.GetKey(i)]=Request.Form[i].ToString();
}
Server.Transfer(Session["DestPage"].ToString(),true);
}
</script>
==============================================================================
<TITLE>FinalPage.aspx</TITLE>
<%@ Page language="c#" %>
<script runat=server>
// This page is just a "proof of concept page"...
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("Shared Session Variable Names/Values between Classic ASP and ASP.NET:<BR>");
for (int i = 0; i < Session.Contents.Count; i++)
{
Response.Write("Assigned to \"" +Session.Keys[i].ToString()+"\"");
Response.Write(" Value: "+ Session[i].ToString() +"<BR>");
}
}
</script>
Update:
Code for where session variable is called on C# page:
private void FillGrid()
{
string connStr = ConfigurationManager.ConnectionStrings["bdsConnectionString"].ConnectionString;
using (SqlConnection Con = new SqlConnection(connStr))
{
Con.Open();
Int32 intresortID = Convert.ToInt32(Request.Form["TypeID"]);
Label4.Text = Convert.ToString(intresortID);
Label4.Visible = true;
DateTime startdate;
startdate = Convert.ToDateTime(TextBox1.Text);
Int32 ed = Convert.ToInt32(TextBox2.Text);
DateTime enddate;
enddate = startdate.AddDays(ed);
string str = "SELECT TOP (100) PERCENT tblAvail.dtm as Dtm, tblResortsRooms.strRoomType as strRoomType, tblResortsRooms.strDescription as strDescription, tblAvail.intQty as intQty, tblAvail.curPrice as curPrice, tblResortsRooms.intWSCode as intWSCode FROM tblAvail INNER JOIN tblResortsRooms ON tblAvail.intResortID = tblResortsRooms.intResortID AND tblAvail.strRoomType = tblResortsRooms.strRoomType WHERE (tblResortsRooms.curRecRate > 0) AND (tblAvail.intResortID = @intResortID) and (tblAvail.dtm between @startdate and @enddate) ORDER BY tblResortsRooms.strRoomType";
SqlDataAdapter sdr = new SqlDataAdapter(str, Con);
sdr.SelectCommand.Parameters.AddWithValue("@intResortID", intresortID);
sdr.SelectCommand.Parameters.AddWithValue("@startdate", startdate);
sdr.SelectCommand.Parameters.AddWithValue("@enddate", enddate);
DataTable dt = new DataTable();
sdr.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
Button2.Visible = true;
}
}
}
Can somebody please show me how?
Bottom line is that a session variable in Classical ASP is not available to ASP.Net (regardless of the language used). You will need to make that value available to the ASP.Net page via a query string or form that gets posted back to the ASP.Net page. So a suggested solution is to pass the value (which apparently is in a session variable in the classical ASP page) via a query string to the ASP.Net page. Then on the ASP.Net page retrieve the query string value and do whatever you want with it.
I hope I haven’t missed the point. But bottom line is there is no interaction between session variables in Classical ASP and ASP.Net because they use completely different frameworks and engines.