views:

86

answers:

2

This has been bugging me for a while but when I databind a control using with a Session variable as the parameter which has not been initialized there is an exception thrown which I can't seem to catch anywhere.

Ideally if the session varaible is not set I would just like to redirect but I can't seem to figure out where I need to check for this instance.

+1  A: 

Hi,

You must check the session object on page_init event.

tekBlues
Thanks that worked nicely!
Stephen Binns
A: 

Check it in your page load.

Sub Page_Load()

if Not Page.ispostback()

if session("Value") <>"" then

me.hiddenfield.value = Session("ValueName")

Else

Response.redirect("PAge.aspx")

End if

End if

End Sub

I tend to add some hidden fields as sessions eventually time out

then make the datasource use the hidden control for its reference

Paul
page load event seems to be too late, interesting about using the hidden control though, i hadn't thought of that
Stephen Binns
It probably will be for the session, for the hidden field it will be ok
Paul