Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ends wits with Session Variables

Status
Not open for further replies.

linuxjr

Programmer
Jun 2, 2001
135
US
I know this is a simple question but its been driving me nuts. I figure I'll ask here since another pair of eyes will see what I'm missing.

I'm just learning asp.net using C# and trying different things out to see how it works. I'm now trying to pass session variables between two pages.

On webform1.aspx I have just a button that is used to call a popup page and here is the code under the Page_Load

Code:
this.btnEngineer.Attributes.Add("OnClick","javascript:window.open('../Popup/webform2.aspx','popup_window','toolbar=0,scrollbars=10, location=0, statusbar=0, menubar=0, resizable=1, width=500, height=500');");

I have now created an Onclick attribute for the button and I have added this code when I press the button:

Code:
private void btnEngineer_Click(object sender, System.EventArgs e)
{
   Response.Write("Engineer");
   Session["sql"] = null;
   Session.Remove("sql");
   Session["sql"] = "select em_id as Engineer from employee";
}

I know the setting session to null and removing is a bit extreme but the problem I'm having is I have added another button and has the same bit of coding as I have posted above with the exception the sql is a different one.

When I run it and press button1 it loads the page up with the data with no problems. When I press the second button it still is holding the old sql statement instead of passing my new one. I close the popup window and press the second button again and it will load the page correctly.

So am I missing something like needing to set a setting on the forms that may not be set correctly or is their a problem using the same session variable name.

Any help or suggestions will be greatly appreciated. Have a great day.
 
lin: I think you might be better off using two Session variables, "sqlA" and "sqlB", in that way they will both be loaded and available for the pop-up window -- you'd have to make a trip back to the server otherwise to clear and reload the Session variable.
 
Isadore,

Thank you for responding to my post. I finally stepped through the debugger setting break points etc and I noticed something.

When the page is first loaded the button get's the onclick attributes loaded with my javascript to opening a window.

When one of the buttons is clicked it will load the session variable with my first sql statement. I can see my simple table with the data populated. Now I close the window(child) and go back to the main window (parent). I click on the second button it automatically fires the javascript code first which the code has the sql statement from the previous button push but after the window finishes loading it clears the session variable under my btnengineer_click and sets it to my new sql. That is what's causing the problem of the pressing the button again.

I'm wondering if you or anyone knows a work around that can allow me to call webform2.aspx as a child popup and still activate the click code in my cs file. Thanks for your time and always any assistance is greatly appreciated.
 
lin: Why not send a QueryString variable (say, 1 and 2); and, depending on which variable arrives on the pop-up aspx page, use it to set the Session sql, then drill the database in the Page Load event of the pop-up window.
 
Isadore,
Thanks for the quick response. I'm working on that right now. If I have any more problems I will post here again. Have a great day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top