session variables and inline code

  • Thread starter Thread starter tony collier
  • Start date Start date
T

tony collier

i can only seem to get access to my session variables in the page_load
function. Any other functions that i write that are called from page_load
or eventdriven do not seem to be able to 'see' the session variables.
Seems to be some sort of scope thing - can someone help me out?
 
shoudn't be so.. i have used session across events etc and no issues with
that.

BTW, what you are trying to do (code snip) would be helpful if you want to
solve your problem.
 
Here is some code:



<script runat="server">

string [] book = (string[])Session["Book"]; //this doesn't find it

void Page_Load(Object sender, EventArgs e)

{
string [] book = (string[])Session["Book"]; //this reads session var OK
screenscrape();
if (!IsPostBack) setcontrols();

}



void screenscrape ()
{
......
}

void setcontrols ()

{
string [] book = (string[])Session["Book"]; //this doesn't find it
book1.Text=book[0];
book2.Text=book[1];
book3.Text=book[2];
}

void addbook ( Object sender, CommandEventArgs e )
{
book[Convert.ToInt32(e.CommandArgument)]=e.CommandName;
Session["Book"]=book; //doesn't work either
}
</script>

html including...

<asp:Button onCommand="addbook" text="add" runat="server"
CommandName="dictionary" CommandArgument="0" />

<asp:Button onCommand="addbook" text="add" runat="server"
CommandName="bible" CommandArgument="1" />

<asp:Button onCommand="addbook" text="add" runat="server"
CommandName="thriller" CommandArgument="2" />





As you can see i have tried string [] book=(string[])Session["Book"] in
various positions but it only works in page_load which is no good because i
need other functions to access it.
 
session variables are accessible anywhere in our code
except the global events(application events)
rest evrywhere it is accessible
u can use httpcontext.current.user.session in cs files
to access session variabes

--
Thanks and Regards,

Amit Agarwal
Software Programmer(.NET)
tony collier said:
Here is some code:



<script runat="server">

string [] book = (string[])Session["Book"]; //this doesn't find it

void Page_Load(Object sender, EventArgs e)

{
string [] book = (string[])Session["Book"]; //this reads session var OK
screenscrape();
if (!IsPostBack) setcontrols();

}



void screenscrape ()
{
.....
}

void setcontrols ()

{
string [] book = (string[])Session["Book"]; //this doesn't find it
book1.Text=book[0];
book2.Text=book[1];
book3.Text=book[2];
}

void addbook ( Object sender, CommandEventArgs e )
{
book[Convert.ToInt32(e.CommandArgument)]=e.CommandName;
Session["Book"]=book; //doesn't work either
}
</script>

html including...

<asp:Button onCommand="addbook" text="add" runat="server"
CommandName="dictionary" CommandArgument="0" />

<asp:Button onCommand="addbook" text="add" runat="server"
CommandName="bible" CommandArgument="1" />

<asp:Button onCommand="addbook" text="add" runat="server"
CommandName="thriller" CommandArgument="2" />





As you can see i have tried string [] book=(string[])Session["Book"] in
various positions but it only works in page_load which is no good because i
need other functions to access it.
 
OK - thanks guys. It is working now, Unfortunately I can't see what
changed to explain this.
 
sorry couldnt help you much earlier. its been a while since i have seen
inline code (asp couple of years back)
 
Back
Top