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.
--
Regards,
HD
Once a Geek... Always a Geek
"tony collier" <melakka@.hotmail.com> wrote in message
news:Xns9486CA42A75D0melakkahotmailcom@.140.99.99.1 30...
>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?
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" <melakka@.hotmail.com> wrote in message
news:Xns9486D7D781F93melakkahotmailcom@.140.99.99.1 30...
> 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.
>
>
>
--
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.577 / Virus Database: 366 - Release Date: 2/3/2004
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)
--
Regards,
HD
Once a Geek... Always a Geek
"tony collier" <melakka@.hotmail.com> wrote in message
news:Xns94876710DED1Cmelakkahotmailcom@.194.117.133 .134...
> OK - thanks guys. It is working now, Unfortunately I can't see what
> changed to explain this.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment