473,562 Members | 2,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Me nu.MenuItem("MI tem", "default.as px", "Home",
False, True))

Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem", "CreateExpenses .aspx",
"New Expenses", False, False))

Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem", "Review.asp x", "Review",
False, False))

'Add it

Session("Menu") = Menu1

Else

'Get it from session

Menu1 = Session("Menu")

End If

Menu1.SetSelect ed(0)
--
Best Regards

The Inimitable Mr Newbie º¿º
Nov 19 '05 #1
7 2032
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******** ******@TK2MSFTN GP09.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.Me nu.MenuItem("MI tem", "default.as px", "Home",
False, True))

Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem", "CreateExpenses .aspx",
"New Expenses", False, False))

Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem", "Review.asp x", "Review",
False, False))

'Add it

Session("Menu") = Menu1

Else

'Get it from session

Menu1 = Session("Menu")

End If

Menu1.SetSelect ed(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***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** *******@TK2MSFT NGP10.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******** ******@TK2MSFTN GP09.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.Me nu.MenuItem("MI tem", "default.as px", "Home",
False, True))

Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem", "CreateExpenses .aspx",
"New Expenses", False, False))

Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem", "Review.asp x",
"Review", False, False))

'Add it

Session("Menu") = Menu1

Else

'Get it from session

Menu1 = Session("Menu")

End If

Menu1.SetSelect ed(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********@csa a.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.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 CreateChildCont rols?). 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******** ******@TK2MSFTN GP11.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***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** *******@TK2MSFT NGP10.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******** ******@TK2MSFTN GP09.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.Me nu.MenuItem("MI tem", "default.as px",
"Home", False, True))

Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem", "CreateExpenses .aspx",
"New Expenses", False, False))

Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem", "Review.asp x",
"Review", False, False))

'Add it

Session("Menu") = Menu1

Else

'Get it from session

Menu1 = Session("Menu")

End If

Menu1.SetSelect ed(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 RetreiveFromSes sion()
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.Me nu.MenuItem("MI tem",
"default.as px", "Home", False, True))
Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem",
"CreateExpenses .aspx", "New Expenses", False, False))
Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem", "Review.asp x",
"Review", False, False))
'Add it
Menu1.SaveInSes sion()

Else

'Get it from session
Menu1.RetreiveF romSession()

End If

Menu1.SetSelect ed(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***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP14.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 CreateChildCont rols?). 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******** ******@TK2MSFTN GP11.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***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** *******@TK2MSFT NGP10.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******** ******@TK2MSFTN GP09.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.Me nu.MenuItem("MI tem", "default.as px",
"Home", False, True))

Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem",
"CreateExpenses .aspx", "New Expenses", False, False))

Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem", "Review.asp x",
"Review", False, False))

'Add it

Session("Menu") = Menu1

Else

'Get it from session

Menu1 = Session("Menu")

End If

Menu1.SetSelect ed(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******** ******@TK2MSFTN GP09.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 RetreiveFromSes sion()
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.Me nu.MenuItem("MI tem",
"default.as px", "Home", False, True))
Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem",
"CreateExpenses .aspx", "New Expenses", False, False))
Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem",
"Review.asp x", "Review", False, False))
'Add it
Menu1.SaveInSes sion()

Else

'Get it from session
Menu1.RetreiveF romSession()

End If

Menu1.SetSelect ed(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***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** ********@TK2MSF TNGP14.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 CreateChildCont rols?). 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******** ******@TK2MSFTN GP11.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***@DIESPAMM ERSDIEtakempis. com> wrote in message
news:%2******** *******@TK2MSFT NGP10.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******** ******@TK2MSFTN GP09.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.Me nu.MenuItem("MI tem", "default.as px",
> "Home", False, True))
>
> Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem",
> "CreateExpenses .aspx", "New Expenses", False, False))
>
> Menu1.Add(New TONEControls.Me nu.MenuItem("MI tem", "Review.asp x",
> "Review", False, False))
>
> 'Add it
>
> Session("Menu") = Menu1
>
> Else
>
> 'Get it from session
>
> Menu1 = Session("Menu")
>
> End If
>
> Menu1.SetSelect ed(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
2138
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 completion and exits) on my RedHat7.3 machine, but it doesn't work (hangs like some thread or queue is blocking)on RH9. However, when I ssh into...
2
1489
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. ************************************************************************ Private Sub lbtnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lbtnSubmit.Click Dim...
14
2351
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 User B has access to 5, now when both of us hits to the server at the same time then their session variables gets mixedup means either User A and...
2
2065
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 "WebNotification". In the WebSite "App1" we create an instance of "WebNotification", but when this class tries to access some Session variables it...
5
2424
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
2505
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 start it and what main topics in C I will need to cover in the assignment. Thanks a lot. CSC180 Assignment #3: Menu Madness Due Date: Thursday,...
1
1655
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
3962
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 like SQL and those 'high level' languages that try to be too clever by half and pack a lot of syntax in as short a space as possible. Like Egyptian...
0
1223
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 only to be able to maintain other people's code. Also, every time I hear such sentiments - "generics/closures/type inference/... are hard to...
0
7658
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7630
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7940
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6228
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5479
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3626
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3609
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1192
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.