473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Session Madness

I have written a Custom Control Menu. Its fairly simple but it works well
enough. In order to simplify things I decided to store the Menu1 custom
control in Session. In the page load event below, it retreives the Menu
from session and assigns its reference to Menu1.

Within the Page_Load event I can see its internal values which have been
retreived for each menu item and so it looks good. However, when the Render
method is called of Menu1, everything seems to have disapeared, there are no
menuitems and the count is zero.

Im sure I am doing something fundamentally stupid, but I cant see it for
staring !

Does anyone have a clue ?

'Check is this is already in Session

If (Session("Menu") Is Nothing) Then

'Build the menu

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "default.aspx", "Home",
False, True))

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "CreateExpenses.aspx",
"New Expenses", False, False))

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "Review.aspx", "Review",
False, False))

'Add it

Session("Menu") = Menu1

Else

'Get it from session

Menu1 = Session("Menu")

End If

Menu1.SetSelected(0)
--
Best Regards

The Inimitable Mr Newbie º¿º
Nov 19 '05 #1
7 2015
How and where is the Menu Control created?

Just as a note, it is generally bad practice to store UI elements in
Session. It is better to store the data they contain in Session.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Complex things are made up of
Lots of simple things.

"Mr Newbie" <he**@now.com> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl...
I have written a Custom Control Menu. Its fairly simple but it works well
enough. In order to simplify things I decided to store the Menu1 custom
control in Session. In the page load event below, it retreives the Menu
from session and assigns its reference to Menu1.

Within the Page_Load event I can see its internal values which have been
retreived for each menu item and so it looks good. However, when the
Render method is called of Menu1, everything seems to have disapeared,
there are no menuitems and the count is zero.

Im sure I am doing something fundamentally stupid, but I cant see it for
staring !

Does anyone have a clue ?

'Check is this is already in Session

If (Session("Menu") Is Nothing) Then

'Build the menu

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "default.aspx", "Home",
False, True))

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "CreateExpenses.aspx",
"New Expenses", False, False))

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "Review.aspx", "Review",
False, False))

'Add it

Session("Menu") = Menu1

Else

'Get it from session

Menu1 = Session("Menu")

End If

Menu1.SetSelected(0)
--
Best Regards

The Inimitable Mr Newbie º¿º

Nov 19 '05 #2
Thanks for your reply Kevin,

OK to answer your questions.

1. How is it created.
The Custom Control, is just that, it resides in a library which is part of
the web solution. The menu is a simple table creation which uses css to set
the background mouseover, mouseout and click events.

The control has an ArrayList collection inside it which stores objects
instantiated from a nested class within the control. These objects are the
menu items themselves containing properties such as href, IsSelected, class
( style sheet class ) etc.

The overriden Render sub takes responsibility for setting up the javascript
for style switching when the mouse events go off.

2.Where
The control is registered as normal as a custom control in the page template
an its ID is Menu1, and is defined in the Codebehind for the Page.

During Page_Load, we detect if the control has been stored in session and if
not, we create the Menu using its Add method and instantiating the MenuItem
anonymously in the constructor. If the Menu has already been stored we
assign its Session("Menu") reference to Menu1. So far so good, we then
select the MenuItem which is currently selected depending on the page it's
on. And this is highlighted as the current position on the site ( Current
Page ).

Everything is fine UNTIL we enter the Render event of the Menu control on
Postback, and although we are in an object, its menuList ( ArrayList
containing the items ) is empty and the count is also empty as if it has
been freshly instantiated.

I'm obviously missing something basic, I hope you will be able to shed some
light on it.

PS: Why is it bad to store the UI objects in Session ( Just interested to
know )

Best Regards

The Inimitable Mr Newbie º¿º


"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
How and where is the Menu Control created?

Just as a note, it is generally bad practice to store UI elements in
Session. It is better to store the data they contain in Session.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Complex things are made up of
Lots of simple things.

"Mr Newbie" <he**@now.com> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl...
I have written a Custom Control Menu. Its fairly simple but it works well
enough. In order to simplify things I decided to store the Menu1 custom
control in Session. In the page load event below, it retreives the Menu
from session and assigns its reference to Menu1.

Within the Page_Load event I can see its internal values which have been
retreived for each menu item and so it looks good. However, when the
Render method is called of Menu1, everything seems to have disapeared,
there are no menuitems and the count is zero.

Im sure I am doing something fundamentally stupid, but I cant see it for
staring !

Does anyone have a clue ?

'Check is this is already in Session

If (Session("Menu") Is Nothing) Then

'Build the menu

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "default.aspx", "Home",
False, True))

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "CreateExpenses.aspx",
"New Expenses", False, False))

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "Review.aspx",
"Review", False, False))

'Add it

Session("Menu") = Menu1

Else

'Get it from session

Menu1 = Session("Menu")

End If

Menu1.SetSelected(0)
--
Best Regards

The Inimitable Mr Newbie º¿º


Nov 19 '05 #3
On the line: Menu1 = Session("Menu"), Your not using either Option
Explict or Option Strict. Maybe the the cast is not correct. This might
account for your not getting out of the session object.

Nov 19 '05 #4
I only wish it were that simple.

I can do this no problem during the page load on GET
Session("Menu") = Menu1 '//Store it
Menu1 = Nothing '// Basically zapping the object set in the page class.
Menu1 = Session("Menu") '// Retreive

And this works OK.

On Postback, it still reads the Menu from the Session, but as soon as you
get into Render on the control, then its lost.

Beats the hell outa me !

--
Best Regards

The Inimitable Mr Newbie º¿º

"CsaaGuy" <ro********@csaa.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
On the line: Menu1 = Session("Menu"), Your not using either Option
Explict or Option Strict. Maybe the the cast is not correct. This might
account for your not getting out of the session object.

Nov 19 '05 #5
Howdy Mr N.,

I kind of suspected that the Control was registered in the Page, and defined
in the CodeBehind. I cannot be sure of this, but I believe this has
something to do with why the Control is not being rendered as expected,
which also brings me to my second point, about which you asked. That is,
that it is not a good idea to store UI elements in Session. So, I'll start
with that.

First, Session exists for every user that is currently using the
application. Whatever users are visiting this particular page, they will
have a copy of the Contro in their Session State. This means that storing
the Control in Session creates a larger footprint (multiplied by the number
of Sessions in which it is stored) than storing only the data. The Control
is a UI element, and therefore contains data and process which does not need
to be stored in memory. Controls are instantiated with each Request, and
pass out of scope when the Page class exits ( matter of milliseconds),
ensuring that they will be Garbage Collected, freeing up server memory
resources. Anything stored in Session remains in state until the Session is
destroyed, which by definition means at least 20 minutes (after the user has
stopped sending Requests for 20 minutes). In other words, a good rule of
thumb is to keep anything that doesn't need to be in Session out of Session.

In addition, this Control is instantiated by the Page class when a Request
is received. Now you have 2 instances of the Control, one more than
necessary, and one which will be discarded in short order, making it
irrelevant. Let's say that you *did* have a reson for storing a Control in
Session (I can't think of one, but for the sake of argument...). There is
therefore no need to have one registred in the page. The Control can be
dynamically added to the Page at run-time.

And that brings me back to the root of your problem. I believe there is a
conflict occurring between the Control registred in the Page, and the
Control stored in Session. It has something to do with (forgive me for not
taking the time to investigate fully) the order in which Controls are
created, stored, and rendered in a Templated Control that contains Child
Controls (the Page). I believe that the Session Control is probably not
being loaded at the right time in the sequence (most probably - remember our
discussion about CreateChildControls?). Somehow, the registred Control is
the one being rendered.

What I would do (and in fact, have done in an app with a very similar type
of menu) is to keep the registered Control in the page, store the ArrayList
in Session, and load the Control from the ArrayList at run-time.

Again, forgive me for not having the time to look extensively into the exact
details. I do love to research, but my wife wants me to spend some time with
her!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
There's a seeker born every minute.
- Dr. "Happy" Harry Cox

"Mr Newbie" <he**@now.com> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
Thanks for your reply Kevin,

OK to answer your questions.

1. How is it created.
The Custom Control, is just that, it resides in a library which is part of
the web solution. The menu is a simple table creation which uses css to
set the background mouseover, mouseout and click events.

The control has an ArrayList collection inside it which stores objects
instantiated from a nested class within the control. These objects are the
menu items themselves containing properties such as href, IsSelected,
class ( style sheet class ) etc.

The overriden Render sub takes responsibility for setting up the
javascript for style switching when the mouse events go off.

2.Where
The control is registered as normal as a custom control in the page
template an its ID is Menu1, and is defined in the Codebehind for the
Page.

During Page_Load, we detect if the control has been stored in session and
if not, we create the Menu using its Add method and instantiating the
MenuItem anonymously in the constructor. If the Menu has already been
stored we assign its Session("Menu") reference to Menu1. So far so good,
we then select the MenuItem which is currently selected depending on the
page it's on. And this is highlighted as the current position on the site
( Current Page ).

Everything is fine UNTIL we enter the Render event of the Menu control on
Postback, and although we are in an object, its menuList ( ArrayList
containing the items ) is empty and the count is also empty as if it has
been freshly instantiated.

I'm obviously missing something basic, I hope you will be able to shed
some light on it.

PS: Why is it bad to store the UI objects in Session ( Just interested to
know )

Best Regards

The Inimitable Mr Newbie º¿º


"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
How and where is the Menu Control created?

Just as a note, it is generally bad practice to store UI elements in
Session. It is better to store the data they contain in Session.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Complex things are made up of
Lots of simple things.

"Mr Newbie" <he**@now.com> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl...
I have written a Custom Control Menu. Its fairly simple but it works well
enough. In order to simplify things I decided to store the Menu1 custom
control in Session. In the page load event below, it retreives the Menu
from session and assigns its reference to Menu1.

Within the Page_Load event I can see its internal values which have been
retreived for each menu item and so it looks good. However, when the
Render method is called of Menu1, everything seems to have disapeared,
there are no menuitems and the count is zero.

Im sure I am doing something fundamentally stupid, but I cant see it for
staring !

Does anyone have a clue ?

'Check is this is already in Session

If (Session("Menu") Is Nothing) Then

'Build the menu

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "default.aspx",
"Home", False, True))

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "CreateExpenses.aspx",
"New Expenses", False, False))

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "Review.aspx",
"Review", False, False))

'Add it

Session("Menu") = Menu1

Else

'Get it from session

Menu1 = Session("Menu")

End If

Menu1.SetSelected(0)
--
Best Regards

The Inimitable Mr Newbie º¿º



Nov 19 '05 #6
Well Kevin, whatever the truth behind the problem, your suggestion saved the
day. I implemented it from within the Menu object. I'm not sure if I really
needed to prefix the menuList identifier with the ControlID, but I was
erring on the side of duplicate ID's. But in this instance, the ID's are
allways likley to be the same anyway so I dont think it matters.

Public Sub SaveInSession()
If Me.Page.Session(Me.ID & "_" & "menuList") Is Nothing Then
Me.Page.Session(Me.ID & "_" & "menuList") = menuList
End If
End Sub

Public Sub RetreiveFromSession()
menuList = Me.Page.Session(Me.ID & "_" & "menuList")
m_count = menuList.Count
End Sub

And in the Page. . . .

'Check is this is already in Session
If Not Page.IsPostBack Then

'Build the menu
Menu1.Add(New TONEControls.Menu.MenuItem("MItem",
"default.aspx", "Home", False, True))
Menu1.Add(New TONEControls.Menu.MenuItem("MItem",
"CreateExpenses.aspx", "New Expenses", False, False))
Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "Review.aspx",
"Review", False, False))
'Add it
Menu1.SaveInSession()

Else

'Get it from session
Menu1.RetreiveFromSession()

End If

Menu1.SetSelected(0)

As allways thanks for taking the time to reply. The issue regarding process
vs data makes sense even if we have not uncovered the underlying problem.

--
Best Regards

The Inimitable Mr Newbie º¿º

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Howdy Mr N.,

I kind of suspected that the Control was registered in the Page, and
defined in the CodeBehind. I cannot be sure of this, but I believe this
has something to do with why the Control is not being rendered as
expected, which also brings me to my second point, about which you asked.
That is, that it is not a good idea to store UI elements in Session. So,
I'll start with that.

First, Session exists for every user that is currently using the
application. Whatever users are visiting this particular page, they will
have a copy of the Contro in their Session State. This means that storing
the Control in Session creates a larger footprint (multiplied by the
number of Sessions in which it is stored) than storing only the data. The
Control is a UI element, and therefore contains data and process which
does not need to be stored in memory. Controls are instantiated with each
Request, and pass out of scope when the Page class exits ( matter of
milliseconds), ensuring that they will be Garbage Collected, freeing up
server memory resources. Anything stored in Session remains in state until
the Session is destroyed, which by definition means at least 20 minutes
(after the user has stopped sending Requests for 20 minutes). In other
words, a good rule of thumb is to keep anything that doesn't need to be in
Session out of Session.

In addition, this Control is instantiated by the Page class when a Request
is received. Now you have 2 instances of the Control, one more than
necessary, and one which will be discarded in short order, making it
irrelevant. Let's say that you *did* have a reson for storing a Control in
Session (I can't think of one, but for the sake of argument...). There is
therefore no need to have one registred in the page. The Control can be
dynamically added to the Page at run-time.

And that brings me back to the root of your problem. I believe there is a
conflict occurring between the Control registred in the Page, and the
Control stored in Session. It has something to do with (forgive me for not
taking the time to investigate fully) the order in which Controls are
created, stored, and rendered in a Templated Control that contains Child
Controls (the Page). I believe that the Session Control is probably not
being loaded at the right time in the sequence (most probably - remember
our discussion about CreateChildControls?). Somehow, the registred Control
is the one being rendered.

What I would do (and in fact, have done in an app with a very similar type
of menu) is to keep the registered Control in the page, store the
ArrayList in Session, and load the Control from the ArrayList at run-time.

Again, forgive me for not having the time to look extensively into the
exact details. I do love to research, but my wife wants me to spend some
time with her!

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
There's a seeker born every minute.
- Dr. "Happy" Harry Cox

"Mr Newbie" <he**@now.com> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
Thanks for your reply Kevin,

OK to answer your questions.

1. How is it created.
The Custom Control, is just that, it resides in a library which is part
of the web solution. The menu is a simple table creation which uses css
to set the background mouseover, mouseout and click events.

The control has an ArrayList collection inside it which stores objects
instantiated from a nested class within the control. These objects are
the menu items themselves containing properties such as href, IsSelected,
class ( style sheet class ) etc.

The overriden Render sub takes responsibility for setting up the
javascript for style switching when the mouse events go off.

2.Where
The control is registered as normal as a custom control in the page
template an its ID is Menu1, and is defined in the Codebehind for the
Page.

During Page_Load, we detect if the control has been stored in session and
if not, we create the Menu using its Add method and instantiating the
MenuItem anonymously in the constructor. If the Menu has already been
stored we assign its Session("Menu") reference to Menu1. So far so good,
we then select the MenuItem which is currently selected depending on the
page it's on. And this is highlighted as the current position on the site
( Current Page ).

Everything is fine UNTIL we enter the Render event of the Menu control on
Postback, and although we are in an object, its menuList ( ArrayList
containing the items ) is empty and the count is also empty as if it has
been freshly instantiated.

I'm obviously missing something basic, I hope you will be able to shed
some light on it.

PS: Why is it bad to store the UI objects in Session ( Just interested to
know )

Best Regards

The Inimitable Mr Newbie º¿º


"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
How and where is the Menu Control created?

Just as a note, it is generally bad practice to store UI elements in
Session. It is better to store the data they contain in Session.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Complex things are made up of
Lots of simple things.

"Mr Newbie" <he**@now.com> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl...
I have written a Custom Control Menu. Its fairly simple but it works
well enough. In order to simplify things I decided to store the Menu1
custom control in Session. In the page load event below, it retreives
the Menu from session and assigns its reference to Menu1.

Within the Page_Load event I can see its internal values which have
been retreived for each menu item and so it looks good. However, when
the Render method is called of Menu1, everything seems to have
disapeared, there are no menuitems and the count is zero.

Im sure I am doing something fundamentally stupid, but I cant see it
for staring !

Does anyone have a clue ?

'Check is this is already in Session

If (Session("Menu") Is Nothing) Then

'Build the menu

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "default.aspx",
"Home", False, True))

Menu1.Add(New TONEControls.Menu.MenuItem("MItem",
"CreateExpenses.aspx", "New Expenses", False, False))

Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "Review.aspx",
"Review", False, False))

'Add it

Session("Menu") = Menu1

Else

'Get it from session

Menu1 = Session("Menu")

End If

Menu1.SetSelected(0)
--
Best Regards

The Inimitable Mr Newbie º¿º



Nov 19 '05 #7
My pleasure, as always, Mr. N!
As allways thanks for taking the time to reply. The issue regarding
process vs data makes sense even if we have not uncovered the underlying
problem.
Yes. Unfortunately, there are only so many hours in a day. No doubt, we
will, either separately or together, encounter and solve the remaining
riddles on another day!

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
There's a seeker born every minute.
- Dr. "Happy" Harry Cox

"Mr Newbie" <he**@now.com> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl... Well Kevin, whatever the truth behind the problem, your suggestion saved
the day. I implemented it from within the Menu object. I'm not sure if I
really needed to prefix the menuList identifier with the ControlID, but I
was erring on the side of duplicate ID's. But in this instance, the ID's
are allways likley to be the same anyway so I dont think it matters.

Public Sub SaveInSession()
If Me.Page.Session(Me.ID & "_" & "menuList") Is Nothing Then
Me.Page.Session(Me.ID & "_" & "menuList") = menuList
End If
End Sub

Public Sub RetreiveFromSession()
menuList = Me.Page.Session(Me.ID & "_" & "menuList")
m_count = menuList.Count
End Sub

And in the Page. . . .

'Check is this is already in Session
If Not Page.IsPostBack Then

'Build the menu
Menu1.Add(New TONEControls.Menu.MenuItem("MItem",
"default.aspx", "Home", False, True))
Menu1.Add(New TONEControls.Menu.MenuItem("MItem",
"CreateExpenses.aspx", "New Expenses", False, False))
Menu1.Add(New TONEControls.Menu.MenuItem("MItem",
"Review.aspx", "Review", False, False))
'Add it
Menu1.SaveInSession()

Else

'Get it from session
Menu1.RetreiveFromSession()

End If

Menu1.SetSelected(0)

As allways thanks for taking the time to reply. The issue regarding
process vs data makes sense even if we have not uncovered the underlying
problem.

--
Best Regards

The Inimitable Mr Newbie º¿º

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Howdy Mr N.,

I kind of suspected that the Control was registered in the Page, and
defined in the CodeBehind. I cannot be sure of this, but I believe this
has something to do with why the Control is not being rendered as
expected, which also brings me to my second point, about which you asked.
That is, that it is not a good idea to store UI elements in Session. So,
I'll start with that.

First, Session exists for every user that is currently using the
application. Whatever users are visiting this particular page, they will
have a copy of the Contro in their Session State. This means that storing
the Control in Session creates a larger footprint (multiplied by the
number of Sessions in which it is stored) than storing only the data. The
Control is a UI element, and therefore contains data and process which
does not need to be stored in memory. Controls are instantiated with each
Request, and pass out of scope when the Page class exits ( matter of
milliseconds), ensuring that they will be Garbage Collected, freeing up
server memory resources. Anything stored in Session remains in state
until the Session is destroyed, which by definition means at least 20
minutes (after the user has stopped sending Requests for 20 minutes). In
other words, a good rule of thumb is to keep anything that doesn't need
to be in Session out of Session.

In addition, this Control is instantiated by the Page class when a
Request is received. Now you have 2 instances of the Control, one more
than necessary, and one which will be discarded in short order, making it
irrelevant. Let's say that you *did* have a reson for storing a Control
in Session (I can't think of one, but for the sake of argument...). There
is therefore no need to have one registred in the page. The Control can
be dynamically added to the Page at run-time.

And that brings me back to the root of your problem. I believe there is a
conflict occurring between the Control registred in the Page, and the
Control stored in Session. It has something to do with (forgive me for
not taking the time to investigate fully) the order in which Controls are
created, stored, and rendered in a Templated Control that contains Child
Controls (the Page). I believe that the Session Control is probably not
being loaded at the right time in the sequence (most probably - remember
our discussion about CreateChildControls?). Somehow, the registred
Control is the one being rendered.

What I would do (and in fact, have done in an app with a very similar
type of menu) is to keep the registered Control in the page, store the
ArrayList in Session, and load the Control from the ArrayList at
run-time.

Again, forgive me for not having the time to look extensively into the
exact details. I do love to research, but my wife wants me to spend some
time with her!

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
There's a seeker born every minute.
- Dr. "Happy" Harry Cox

"Mr Newbie" <he**@now.com> wrote in message
news:ew**************@TK2MSFTNGP11.phx.gbl...
Thanks for your reply Kevin,

OK to answer your questions.

1. How is it created.
The Custom Control, is just that, it resides in a library which is part
of the web solution. The menu is a simple table creation which uses css
to set the background mouseover, mouseout and click events.

The control has an ArrayList collection inside it which stores objects
instantiated from a nested class within the control. These objects are
the menu items themselves containing properties such as href,
IsSelected, class ( style sheet class ) etc.

The overriden Render sub takes responsibility for setting up the
javascript for style switching when the mouse events go off.

2.Where
The control is registered as normal as a custom control in the page
template an its ID is Menu1, and is defined in the Codebehind for the
Page.

During Page_Load, we detect if the control has been stored in session
and if not, we create the Menu using its Add method and instantiating
the MenuItem anonymously in the constructor. If the Menu has already
been stored we assign its Session("Menu") reference to Menu1. So far so
good, we then select the MenuItem which is currently selected depending
on the page it's on. And this is highlighted as the current position on
the site ( Current Page ).

Everything is fine UNTIL we enter the Render event of the Menu control
on Postback, and although we are in an object, its menuList ( ArrayList
containing the items ) is empty and the count is also empty as if it has
been freshly instantiated.

I'm obviously missing something basic, I hope you will be able to shed
some light on it.

PS: Why is it bad to store the UI objects in Session ( Just interested
to know )

Best Regards

The Inimitable Mr Newbie º¿º


"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
How and where is the Menu Control created?

Just as a note, it is generally bad practice to store UI elements in
Session. It is better to store the data they contain in Session.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Complex things are made up of
Lots of simple things.

"Mr Newbie" <he**@now.com> wrote in message
news:up**************@TK2MSFTNGP09.phx.gbl...
>I have written a Custom Control Menu. Its fairly simple but it works
>well enough. In order to simplify things I decided to store the Menu1
>custom control in Session. In the page load event below, it retreives
>the Menu from session and assigns its reference to Menu1.
>
> Within the Page_Load event I can see its internal values which have
> been retreived for each menu item and so it looks good. However, when
> the Render method is called of Menu1, everything seems to have
> disapeared, there are no menuitems and the count is zero.
>
> Im sure I am doing something fundamentally stupid, but I cant see it
> for staring !
>
> Does anyone have a clue ?
>
> 'Check is this is already in Session
>
> If (Session("Menu") Is Nothing) Then
>
> 'Build the menu
>
> Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "default.aspx",
> "Home", False, True))
>
> Menu1.Add(New TONEControls.Menu.MenuItem("MItem",
> "CreateExpenses.aspx", "New Expenses", False, False))
>
> Menu1.Add(New TONEControls.Menu.MenuItem("MItem", "Review.aspx",
> "Review", False, False))
>
> 'Add it
>
> Session("Menu") = Menu1
>
> Else
>
> 'Get it from session
>
> Menu1 = Session("Menu")
>
> End If
>
> Menu1.SetSelected(0)
>
>
> --
> Best Regards
>
> The Inimitable Mr Newbie º¿º
>



Nov 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lane LiaBraaten | last post by:
I am developing a GUI that uses multiple threading.Threads, and Queue.Queues for communicating between the threads, and threading.Timers for checking the queues. Everything works well (runs to...
2
by: Todd | last post by:
Here's one that has been stumping people: I'm writing in ASPX with VB.NET On the login page I set the entered usename text to a session variable....
14
by: aroraamit81 | last post by:
Hi, I am facing a trouble. I have some Session variables in my code and somehow my session variables are getting mixed up with other users. For example User A has access to 10 companies and...
2
by: ras26 | last post by:
I have a WebSite "App1" which has an external assembly "Lib1". Inside this external assembly we have developed some classes that derive from "System.Web.UI.Page". One of these pages is called...
5
by: lyealain | last post by:
<% If Session("username") = "" Then Response.Redirect("/CLS/Login.asp") End If Dim conn Dim connectstr Dim db_name, db_username, db_userpassword Dim db_server Dim res
1
by: Kayvine | last post by:
Hi guys, this is a question I have for an assignment, it is pretty long, but I am not asking for the code(well if someone wants to write I'll be really happy, lol), but I just want to know how to...
1
by: =?Utf-8?B?SmFja2Rhdw==?= | last post by:
Hi! I just up-graded my "Dell Help & Support Center" and now every time I start upthe Dell folder is open on the desk top. How do I make it GO AWAY, lest madness overtake me. Thanks! -- DAW
20
by: raylopez99 | last post by:
Took a look at all the fuss about "lambda expressions" from Jon Skeet's excellent book "C# in Depth". Jon has an example, reproduced below (excerpt) on lambda expressions. My n00b take: it's...
0
by: Pavel Minaev | last post by:
On Aug 14, 1:37 pm, raylopez99 <raylope...@yahoo.comwrote: You are, of course, entitled to your opinion, but lambdas are a part of C# 3.0, and any C# developer has to know their ins and outs if...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.