Showing posts with label form. Show all posts
Showing posts with label form. Show all posts

Thursday, March 29, 2012

Session Values are lost

Hello everyone,

I have a problem I have no idea why it happens.
I have an ASP.NET application that has around 7 forms.
To move from one form to another I use "redirect".
I also use around 12 Session items that I fill with different values
like for ex.: Session.item("EmployeeName")="LILIA"
98% of the time everything is OK.
However once "in a blue moon" I find that the value in
Session.item("EmployeeName") is lost.
I am sure is not an expiration time since this happens after only a
couple of minutes.
Any help will be very much appreciated.

Thanks,

LilianaIf you are convinced that it isn't the timout its almost for sure that the
application gets restarted for some reason.
Causes are editing wec.config,gloval.asax,...

Cheers,
Tom Pester

> Hello everyone,
> I have a problem I have no idea why it happens.
> I have an ASP.NET application that has around 7 forms.
> To move from one form to another I use "redirect".
> I also use around 12 Session items that I fill with different values
> like for ex.: Session.item("EmployeeName")="LILIA"
> 98% of the time everything is OK.
> However once "in a blue moon" I find that the value in
> Session.item("EmployeeName") is lost.
> I am sure is not an expiration time since this happens after only a
> couple of minutes.
> Any help will be very much appreciated.
> Thanks,
> Liliana
You must be sure follow issues:
1.Would you modify your application's bin directory.
2.May be your aspnet_wp.exe(in window2000 or xp) was recycled.
--
Help you,Help me.

"LiliA" wrote:

> Hello everyone,
> I have a problem I have no idea why it happens.
> I have an ASP.NET application that has around 7 forms.
> To move from one form to another I use "redirect".
> I also use around 12 Session items that I fill with different values
> like for ex.: Session.item("EmployeeName")="LILIA"
> 98% of the time everything is OK.
> However once "in a blue moon" I find that the value in
> Session.item("EmployeeName") is lost.
> I am sure is not an expiration time since this happens after only a
> couple of minutes.
> Any help will be very much appreciated.
> Thanks,
> Liliana
>

Session variable

Hello,

I have a form with a button that opens a new browser with another form. I
want to be able to change a session variable before the new form is loaded.
Can this be done? If yes, how? Thank you in advance and your help is greatly
appreciated.Uytkownik "James" <james@.nodomain.netnapisa w wiadomoci
news:%23orOxZppGHA.3324@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

Hello,
>
>
I have a form with a button that opens a new browser with another form. I
want to be able to change a session variable before the new form is
loaded. Can this be done? If yes, how? Thank you in advance and your help
is greatly appreciated.


For me there is only one solution. On the second page in Page_Load method
change this variable.

--
JS
BRE Bank Dev Team, Poland
You would put all the code in the server-side button click handler. e.g.,

Session["myValue"]="new value";
Response.Write("<script>window.Open("hewpage.aspx");</script>");

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"James" wrote:

Quote:

Originally Posted by

Hello,
>
>
I have a form with a button that opens a new browser with another form. I
want to be able to change a session variable before the new form is loaded.
Can this be done? If yes, how? Thank you in advance and your help is greatly
appreciated.
>
>
>


It's good to know people who know what they are doing!

Thanks, it worked great!

"Peter Bromberg [C# MVP]" <pbromberg@.yahoo.nospammin.comwrote in message
news:F6B66951-B4B5-4F69-A709-F163BA74EAA1@.microsoft.com...

Quote:

Originally Posted by

You would put all the code in the server-side button click handler. e.g.,
>
Session["myValue"]="new value";
Response.Write("<script>window.Open("hewpage.aspx");</script>");
>
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"James" wrote:
>

Quote:

Originally Posted by

>Hello,
>>
>>
>I have a form with a button that opens a new browser with another form. I
>want to be able to change a session variable before the new form is
>loaded.
>Can this be done? If yes, how? Thank you in advance and your help is
>greatly
>appreciated.
>>
>>
>>

Session variable and Back

I am using a session variable to store a value that added when a person goes through multiple pages on a form, basically a scorecard. If the person hits the Back button to redo a value, how do I restore the original value before they hit submit again? Right now the old value and the new value are being added together.

thanks

You need to "disable" the browser's Back button's functionality so that it does not load the page from the browser cache but hits the same page again. See this post for details:

http://geekswithblogs.net/vivek/archive/2007/02/24/107148.aspx

So whenever user presses back button the page_load event will fire again and you can put the relevant session setting/modifying code there.

Hope this helps,

Vivek


You could store the value to be passed in a hidden form input. That way the value will always be what it was when the page was posted.

Session variable and postback question

Hello,
I have this web form where I have something like

--In pageload

If not ispostback then
session("drc") = ......
end if

and I intend to use this drc(datarowcollection) throughout a user session.

My problem is this: When a postback occurs because of say a buttonclick or radiobutton click then everything happens as I expect it to work. But when in the middle of a session I press the Refresh button of the browser (IE), then it goes into the code above i.e. page.postback = false. Because of this, I am facing a lot of difficulty. Is this something to do with the session variable. Is there another way in which I can store the datarowcollection so that I can use the same throughout the session.

_Please Help_. I would really appreciate it.

Thanks,
dotosuSo if it is NOT a postback you check for the existence of the session variable and if it does NOT exist you create what you need and then store it in there? Or you just assume that the session variable is not in there at all?
But my question is if say session.timeout = 20 and I go to this page in question and move around for 5 minutes, everything is working fine but then if I hit the Refresh button on the browser then it goes into If not page.ispostback statement. Now, it is not supposed to do this since it is not really bringing up the page for the first time, right?

Am I missing something here?

PLEASE HELP!!

Thanks, dotosu
Would anyone know why this might be happening. I would greatly appreciate help.

-dotosu
To the web server it is bringing up the page for the first time whether the session has timed out or not. This is if you do a refresh without first doing a postback.

I don't think I understand what your difficulty is here. Could you try to explain it another way and maybe I can offer more help?
I think I am sort of confused here. Please check my first post in this thread for an explanation of what my problem is. I don't think I can explain it any better but I sure need some help with this.

Now as far as I understand, we have such a sub

Sub Page_Load(...)
If Not IsPostback Then
'do something for situations when the page is first brought up
Else
' do something for situations when the page is brought up after first time
End If
End Sub
Do I not understand this correctly?

Thanks,
dotosu
Try this;

If Page.IsPostBack = False Then

'check if a session already exist
If Session("drc") = 0 Then
'set the session
Session("drc") = "yourinfo"
end if
</code
Hope this helps..
Sorry about my last oversight

Try this;


If Page.IsPostBack = False Then

'check if a session already exist
If Len(Session("drc")) = 0 Then
'set the session
Session("drc") = yourinfo
end if

Len is for the expression object (zero) as integer

Saturday, March 24, 2012

session variable only accessable through page behind class instance?

Are session variables available to any class instance within a project namespace or only for use for the form codebehind class?

I have tried to set a session variable on a code behind class and then retrieve its value in a class instance used by the codebehind class and I get errors. Maybe I'm just not meant to access that way and only codebehind classes (classes that inherit System.Web.UI.Page) can use them?As far as I know session variables are only available in aspx pages.

That does not prevent you from passing value of your session variables to any of your business tier objects.
It's more a question of context.
Within the context of the ASP.NET process, any class can get to the session using HttpContext.Current.Session.
Thanks very much for the help!

Session variable problem

Hi,

Im having trouble with the code below, I think it is because this code is executed in a class and not on an actual form, I am getting the error "Name 'Session' is not declared.

Is there away to fix this error? Is there an problems with setting the user session variable in a class and not on a form?

Private Function PasswordMatch(ByVal UserName, ByVal PassEntered)
Try
Dim intResult As Integer = 0
Dim intUser As Integer
SqlCmdLogon.CommandText = "sp_CheckPassword"
SqlCmdLogon.Parameters("@dotnet.itags.org.Username").Value = UserName
SqlCmdLogon.Parameters("@dotnet.itags.org.Password").Value = PassEntered
SqlCnnShippers.Open()
SqlCmdLogon.ExecuteNonQuery()
intResult = SqlCmdLogon.Parameters("@dotnet.itags.org.Rows").Value
intUser = SqlCmdLogon.Parameters("@dotnet.itags.org.UserID").Value
If intResult = -1 Then

session("UserID") = SqlCmdLogon.Parameters("@dotnet.itags.org.UserID").Value

Return True
Else
Return False
End IfApparently it is not possible, so passed it to a public readonly property instead then called that on the form to set the session variable instead.

Should be Ok.

I'll mark resolved but if anyone sees aproblem ps let me know.
Can i know how we check there is what stored inside the session?
Session("Name") ="Fish"
label1.text = Session("Name")
'Label should display "Fish"
Apparently it is not possible, so passed it to a public readonly property instead then called that on the form to set the session variable instead.

Should be Ok.

I'll mark resolved but if anyone sees aproblem ps let me know.
That's how it was supposed to be done. You can't let your HTTPContexts be mixed into your class logic.