Thursday, March 29, 2012

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

0 comments:

Post a Comment