Showing posts with label varaibles. Show all posts
Showing posts with label varaibles. Show all posts

Thursday, March 29, 2012

session varaibles with asp.net urgent help

hi i store some value in session object and later try to access it but the
value return from session variable is null
like
Session["Myname"]=txtmyname.Text;
Session["Age"]=txtAge.Text;
Response.Redirect("Welcome.aspx");
when this page loaded and iin page load event i called
lblMyname.Text=(string)session["Myname"];
lblAge.Text=(string)session["Age"];
it return null value instead of actual values.
i tried to store session value both in sql database and local memory both
result are sameamjad wrote:

Quote:

Originally Posted by

hi i store some value in session object and later try to access it but the
value return from session variable is null
like
Session["Myname"]=txtmyname.Text;
Session["Age"]=txtAge.Text;
Response.Redirect("Welcome.aspx");
when this page loaded and iin page load event i called
lblMyname.Text=(string)session["Myname"];
lblAge.Text=(string)session["Age"];
it return null value instead of actual values.
i tried to store session value both in sql database and local memory both
result are same


The possible chances are these:
1. you have started session somewhere else (on anyother page) as well
and
session is not abondened yet (with session.abonden).

2.

Quote:

Originally Posted by

lblMyname.Text=(string)session["Myname"]; //session's s should be capital i.e Session


3. or try this instead

lblMyname.Text=Session["email"].ToString();
3.
lblAge.Text=Session["Age"].ToString()
its not the Session i wrote small otherwise c # cannot compile. . i have
cancelled the session variable but still cannt display that value in another
page.

"nasirmajor@.yahoo.com" wrote:

Quote:

Originally Posted by

>
amjad wrote:

Quote:

Originally Posted by

hi i store some value in session object and later try to access it but the
value return from session variable is null
like
Session["Myname"]=txtmyname.Text;
Session["Age"]=txtAge.Text;
Response.Redirect("Welcome.aspx");
when this page loaded and iin page load event i called
lblMyname.Text=(string)session["Myname"];
lblAge.Text=(string)session["Age"];
it return null value instead of actual values.
i tried to store session value both in sql database and local memory both
result are same


>
The possible chances are these:
1. you have started session somewhere else (on anyother page) as well
and
session is not abondened yet (with session.abonden).
>
2.

Quote:

Originally Posted by

lblMyname.Text=(string)session["Myname"]; //session's s should be capital i.e Session


>
>
3. or try this instead
>
lblMyname.Text=Session["email"].ToString();
>
>


where have you cancelled/cleared the session?
when i do that instead of (string)Session["Age"] then it gave me that error
System.NullReferenceException: Object reference not set to an instance of an
object.

"nasirmajor@.yahoo.com" wrote:

Quote:

Originally Posted by

>
3.
lblAge.Text=Session["Age"].ToString()
>
>


amjad wrote:

Quote:

Originally Posted by

when i do that instead of (string)Session["Age"] then it gave me that error
System.NullReferenceException: Object reference not set to an instance of an
object.
>
>
"nasirmajor@.yahoo.com" wrote:
>

Quote:

Originally Posted by


3.
lblAge.Text=Session["Age"].ToString()


where ever if you have used session.clear or session.removeall replace
it with
session.abondon();
try whats happen?

Session varaibles are lost when an error occurs

In VS2003, when debugging (with breakpoints set) a ASP.net web project
(locally), if an error/exception occurs the browser navigates to the "Server
Error" page. After this point it looses all the values stored in the Session
objects, and leads to many other errors, before I must refresh the page and
restart all over again. What the problem can be?
Thanks in advance.Hi,
Before redirecting to the error page the current session is distroyed and a
new session is created. This is the ASP.NET behavior. What you can do is to
catch all unhandled exceptions in the Application_Error from Global file. In
this handler you should clean the error and manually redirect to your custom
error page using Server.Transfer method. This way you prevent the
application from distroying the session.
"So" <.> wrote in message news:O38eKVIUFHA.2712@.TK2MSFTNGP09.phx.gbl...
> In VS2003, when debugging (with breakpoints set) a ASP.net web project
> (locally), if an error/exception occurs the browser navigates to the
"Server
> Error" page. After this point it looses all the values stored in the
Session
> objects, and leads to many other errors, before I must refresh the page
and
> restart all over again. What the problem can be?
> Thanks in advance.
>
Thanks for your reply. Sorry for getting back late.
I tried to do something like this below in global.asax.vb, but I am still
loosing the Session variables. Note that I am not redirecting to any error
page at the moment. What more can be done, and where (on web/docu) can I
read in good details about the ASP.net session handling?
Protected Sub Application_Error(ByVal sender As [Object], ByVal e As
EventArgs)
Dim objErr As Exception =
Server.GetLastError().GetBaseException()
Server.ClearError()
Dim err As String = "<b>Error Caught in Application_Error
event</b><hr><br>" & _
"<br><b>Error in: </b>" &
Request.Url.ToString() & _
"<br><b>Error Message: </b>" &
objErr.Message.ToString() & _
"<br><b>Stack Trace:</b><br>" &
objErr.StackTrace.ToString().Replace("at ", "<br>at ") & _
"<br><a
href='java script:window.location.reload()'>Refresh</a>"
Response.Write(err.ToString())
End Sub
Thanks again for your time.
"Mircea Pleteriu" <mpleteriu@.newsgroup.nospam> schrieb im Newsbeitrag
news:eO46FqJUFHA.228@.TK2MSFTNGP12.phx.gbl...
> Hi,
> Before redirecting to the error page the current session is distroyed and
a
> new session is created. This is the ASP.NET behavior. What you can do is
to
> catch all unhandled exceptions in the Application_Error from Global file.
In
> this handler you should clean the error and manually redirect to your
custom
> error page using Server.Transfer method. This way you prevent the
> application from distroying the session.
> "So" <.> wrote in message news:O38eKVIUFHA.2712@.TK2MSFTNGP09.phx.gbl...
> "Server
> Session
> and
>

Session varaibles are lost when an error occurs

In VS2003, when debugging (with breakpoints set) a ASP.net web project
(locally), if an error/exception occurs the browser navigates to the "Server
Error" page. After this point it looses all the values stored in the Session
objects, and leads to many other errors, before I must refresh the page and
restart all over again. What the problem can be?

Thanks in advance.Hi,

Before redirecting to the error page the current session is distroyed and a
new session is created. This is the ASP.NET behavior. What you can do is to
catch all unhandled exceptions in the Application_Error from Global file. In
this handler you should clean the error and manually redirect to your custom
error page using Server.Transfer method. This way you prevent the
application from distroying the session.

"So" <.> wrote in message news:O38eKVIUFHA.2712@.TK2MSFTNGP09.phx.gbl...
> In VS2003, when debugging (with breakpoints set) a ASP.net web project
> (locally), if an error/exception occurs the browser navigates to the
"Server
> Error" page. After this point it looses all the values stored in the
Session
> objects, and leads to many other errors, before I must refresh the page
and
> restart all over again. What the problem can be?
> Thanks in advance.