467,915 Members | 1,884 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

asp.net 2.0 master pages problem

Hi there,

I've created a master page with some controls on it, a Calendar control
among others. Now depending on the date(s) selected, the content page needs
to be updated. In the masterpage I've created StartDate and EndDate
properties, which are basically wrappers around the SelectedDates property
from the Calendar control.

When I select another date in the Calendar, the page updates normally, but
when Page_Load for the content page fires, the selected dates aren't updated
yet. The problem is probably that the content page gets updated first, and
then the master page.

How do I work around this problem? Or is this more like a bug in the
framework? Matbe what should happen, is that both the master page *and* the
content page should be updated, and *then* the Page_Load event(s) should be
called.

Anyone has any input on this?

--
Thanks,

Martijn Saly
Nov 19 '05 #1
  • viewed: 1672
Share:
7 Replies
The SelectedDate property of the Calendar will not be updated until
the calendar's SelectionChanged event fires (which will be after
Page_Load for both the content page and the master).

Yes, I think the Calendar is a bit quirky in this respect. Any other
control that has an 'auto-postback' will be updated by Page_Load.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 10 Sep 2005 12:08:36 +0200, Martijn Saly <ma*****@thany.org>
wrote:
Hi there,

I've created a master page with some controls on it, a Calendar control
among others. Now depending on the date(s) selected, the content page needs
to be updated. In the masterpage I've created StartDate and EndDate
properties, which are basically wrappers around the SelectedDates property
from the Calendar control.

When I select another date in the Calendar, the page updates normally, but
when Page_Load for the content page fires, the selected dates aren't updated
yet. The problem is probably that the content page gets updated first, and
then the master page.

How do I work around this problem? Or is this more like a bug in the
framework? Matbe what should happen, is that both the master page *and* the
content page should be updated, and *then* the Page_Load event(s) should be
called.

Anyone has any input on this?


Nov 19 '05 #2
Scott, your closing statement is not neccessarily correct when controls are
used in MasterPages.

A LinkButton that is a child of a Panel located in a MasterPage will not and
need not raise a PostBack event when the LinkButton click event is raised.
Furthermore, the controls disappear from the ViewState reverting to their
state before any click events were raised (why in my circumstances is now
undestood but how to respond has brought me to a stand still).

I begin to discuss the topic at the ASP.NET Forums [1] and have been trying
to get the attention of somebody like yourself who has done the early work
with 2.0 to help debug and make sense of how to respond to controls that
simply disappear from ViewState. Will you take it on with me here on in the
forums?

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1] http://forums.asp.net/1039817/ShowPost.aspx
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:vb********************************@4ax.com...
The SelectedDate property of the Calendar will not be updated until
the calendar's SelectionChanged event fires (which will be after
Page_Load for both the content page and the master).

Yes, I think the Calendar is a bit quirky in this respect. Any other
control that has an 'auto-postback' will be updated by Page_Load.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 10 Sep 2005 12:08:36 +0200, Martijn Saly <ma*****@thany.org>
wrote:
Hi there,

I've created a master page with some controls on it, a Calendar control
among others. Now depending on the date(s) selected, the content page
needs
to be updated. In the masterpage I've created StartDate and EndDate
properties, which are basically wrappers around the SelectedDates property
from the Calendar control.

When I select another date in the Calendar, the page updates normally, but
when Page_Load for the content page fires, the selected dates aren't
updated
yet. The problem is probably that the content page gets updated first, and
then the master page.

How do I work around this problem? Or is this more like a bug in the
framework? Matbe what should happen, is that both the master page *and*
the
content page should be updated, and *then* the Page_Load event(s) should
be
called.

Anyone has any input on this?

Nov 19 '05 #3
Scott Allen wrote:
The SelectedDate property of the Calendar will not be updated until
the calendar's SelectionChanged event fires (which will be after
Page_Load for both the content page and the master).
Not true, when selecting a date, I can clearly see while debugging the
Page_load event of the master page, that SelectedDates is updated as expected.
Yes, I think the Calendar is a bit quirky in this respect. Any other
control that has an 'auto-postback' will be updated by Page_Load.


The problem is that the master page should be updated before the content
page. Now it's the other way around, and therefor a content page cannot know
about any changes in any control on its master page.

--
Thanks,

Martijn Saly
Nov 19 '05 #4
On Sat, 10 Sep 2005 18:52:52 +0200, Martijn Saly <ma*****@thany.org>
wrote:
Scott Allen wrote:
The SelectedDate property of the Calendar will not be updated until
the calendar's SelectionChanged event fires (which will be after
Page_Load for both the content page and the master).


Not true, when selecting a date, I can clearly see while debugging the
Page_load event of the master page, that SelectedDates is updated as expected.


Are we talking about a date selected by the user who clicked on a new
day / week in the Calendar control? This calendar will not know the
date until the logic in RaisePostBackEvent executes, which is after
Page_Load. The code for a form at the bottom of this post will
demonstrate this fact by checking the SelectedDate property during
Page_Load, and during Page_PreRender (which is after
RaisePostBackEvent). The 2 labels on the form will show different
dates when you start clicking on links.
Yes, I think the Calendar is a bit quirky in this respect. Any other
control that has an 'auto-postback' will be updated by Page_Load.


The problem is that the master page should be updated before the content
page. Now it's the other way around, and therefor a content page cannot know
about any changes in any control on its master page.


Ah - I think I understand the problem now. When you say "selecting a
date" you mean programatically, not by clicking on the Calendar at
runtime, right?

The way master pages are implemented they become a child control in
the content page's Controls collection, thus Page_Load for the content
page will always fire before Page_Load in the master page:

http://odetocode.com/Blogs/scott/arc...9/10/2179.aspx
It's handy to think of the master page as just another user control on
the page when it comes time to executing logic in response to events.

Code:

<%@ Page Language="C#" %>

<script runat="server">
void Page_Load(object o, EventArgs e)
{
LoadLabel.Text = Calendar1.SelectedDate.ToString();
}

void Page_PreRender(object o, EventArgs e)
{
PreRenderLabel.Text = Calendar1.SelectedDate.ToString();
}
</script>

<html>
<head runat="server">
<title>Calendar</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar runat="server" ID="Calendar1"/>
<br />
<asp:Label runat="server" ID="LoadLabel"/>
<br />
<asp:Label runat="server" ID="PreRenderLabel" />
</div>
</form>
</body>
</html>
--
Scott
http://www.OdeToCode.com/blogs/scott/

Nov 19 '05 #5
Can you give me some code to try myself? I'll definitely take a look.
Feel free to email me, too.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 10 Sep 2005 11:12:31 -0500, "clintonG"
<cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote:
Scott, your closing statement is not neccessarily correct when controls are
used in MasterPages.

A LinkButton that is a child of a Panel located in a MasterPage will not and
need not raise a PostBack event when the LinkButton click event is raised.
Furthermore, the controls disappear from the ViewState reverting to their
state before any click events were raised (why in my circumstances is now
undestood but how to respond has brought me to a stand still).

I begin to discuss the topic at the ASP.NET Forums [1] and have been trying
to get the attention of somebody like yourself who has done the early work
with 2.0 to help debug and make sense of how to respond to controls that
simply disappear from ViewState. Will you take it on with me here on in the
forums?

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1] http://forums.asp.net/1039817/ShowPost.aspx
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:vb********************************@4ax.com.. .
The SelectedDate property of the Calendar will not be updated until
the calendar's SelectionChanged event fires (which will be after
Page_Load for both the content page and the master).

Yes, I think the Calendar is a bit quirky in this respect. Any other
control that has an 'auto-postback' will be updated by Page_Load.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 10 Sep 2005 12:08:36 +0200, Martijn Saly <ma*****@thany.org>
wrote:
Hi there,

I've created a master page with some controls on it, a Calendar control
among others. Now depending on the date(s) selected, the content page
needs
to be updated. In the masterpage I've created StartDate and EndDate
properties, which are basically wrappers around the SelectedDates property
from the Calendar control.

When I select another date in the Calendar, the page updates normally, but
when Page_Load for the content page fires, the selected dates aren't
updated
yet. The problem is probably that the content page gets updated first, and
then the master page.

How do I work around this problem? Or is this more like a bug in the
framework? Matbe what should happen, is that both the master page *and*
the
content page should be updated, and *then* the Page_Load event(s) should
be
called.

Anyone has any input on this?


Nov 19 '05 #6
As it turns out I've been trying to build my own tabbed navigation and am
now going to try to do so using a Menu control that will load SiteMapPath
controls instead of LinkButtons and Panel controls but I do want to follow
through on the issue I raised as there is an important issue related to
referencing controls that I have not mastered (pun intended) when using
MasterPages.

The former method I've been asking questions about used LinkButtons to
change visibility for a Panel control which contained other LinkButtons used
to load content pages in the master. When I attempted to use the LinkButton
which is the child of the Panel the content page would load but the Panel
and its child controls would disappear.

Somebody finally pointed out the reason the control state was being lost was
because I was actually navigating and not using a PostBack and actually just
reloading the MasterPage in the same state it was before the LinkButton
event was used to load a content page. I understand that but still need to
master how to access a child control such as a LinkButton when it is a child
of the Panel which is in the MasterPage.

Your otherwise outstanding article "In Search of ASP.NET Controls" [1] was
helpful and a frequent reference but did not hit the sweet spot for me in
this unique circumstance when using MasterPages primarily I believe because
your focus while writing the article was the use of the FindControl method
which is rather easy to use when controls are in the page but not when a
control is a child of a control in the page when using MasterPages.

I even tried using the new Cross-Page Posting, PostBackUrl and PreviousPage
property which will pass the control state to the new page but I could not
reference that LinkButton child of the Panel.

Mood: braindead ;-)

<%= Clinton Gallagher

[1] http://www.odetocode.com/Articles/116.aspx


"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:jj********************************@4ax.com...
Can you give me some code to try myself? I'll definitely take a look.
Feel free to email me, too.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 10 Sep 2005 11:12:31 -0500, "clintonG"
<cs*********@REMOVETHISTEXTmetromilwaukee.com> wrote:
Scott, your closing statement is not neccessarily correct when controls
are
used in MasterPages.

A LinkButton that is a child of a Panel located in a MasterPage will not
and
need not raise a PostBack event when the LinkButton click event is raised.
Furthermore, the controls disappear from the ViewState reverting to their
state before any click events were raised (why in my circumstances is now
undestood but how to respond has brought me to a stand still).

I begin to discuss the topic at the ASP.NET Forums [1] and have been
trying
to get the attention of somebody like yourself who has done the early work
with 2.0 to help debug and make sense of how to respond to controls that
simply disappear from ViewState. Will you take it on with me here on in
the
forums?

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1] http://forums.asp.net/1039817/ShowPost.aspx
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:vb********************************@4ax.com. ..
The SelectedDate property of the Calendar will not be updated until
the calendar's SelectionChanged event fires (which will be after
Page_Load for both the content page and the master).

Yes, I think the Calendar is a bit quirky in this respect. Any other
control that has an 'auto-postback' will be updated by Page_Load.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 10 Sep 2005 12:08:36 +0200, Martijn Saly <ma*****@thany.org>
wrote:

Hi there,

I've created a master page with some controls on it, a Calendar control
among others. Now depending on the date(s) selected, the content page
needs
to be updated. In the masterpage I've created StartDate and EndDate
properties, which are basically wrappers around the SelectedDates
property
from the Calendar control.

When I select another date in the Calendar, the page updates normally,
but
when Page_Load for the content page fires, the selected dates aren't
updated
yet. The problem is probably that the content page gets updated first,
and
then the master page.

How do I work around this problem? Or is this more like a bug in the
framework? Matbe what should happen, is that both the master page *and*
the
content page should be updated, and *then* the Page_Load event(s) should
be
called.

Anyone has any input on this?

Nov 19 '05 #7

Mood: braindead ;-)


:)

Me too...
--
Scott
http://www.OdeToCode.com/blogs/scott/
Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Michael Herman \(Parallelspace\) | last post: by
8 posts views Thread by otto | last post: by
7 posts views Thread by xkeops | last post: by
2 posts views Thread by Argirop | last post: by
3 posts views Thread by Rich | last post: by
6 posts views Thread by =?Utf-8?B?SmF5IFBvbmR5?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.