473,387 Members | 1,582 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,387 software developers and data experts.

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
7 1928
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Michael Herman \(Parallelspace\) | last post by:
1. What are some compelling solutions for using Master/Content pages with Web Pages? 2. If a content area has a web part zone with web parts, what is the user experience like when "editting" the...
20
by: Alan Silver | last post by:
Hello, In classic ASP, I used to use two include files on each page, one before and one after the main content, to provide a consistent layout across a web site. That way I could just change the...
1
by: Alan Silver | last post by:
Hello, I am just experimenting with master pages, and am trying to add a content placeholder in the <head> section, so that individual pages can set their own page title and meta tags. The...
4
by: EagleRed | last post by:
I am writing an ASP.NET 2.0 application that uses more than one master page. Currently, there are two pages, Freedom1.master and Freedom2.master. I have no problems with Freedom1.master. However,...
8
by: otto | last post by:
Hi, all: I have a problem with the inclusion of .js files in mu .aspx pages when using Master Pages. I try to explain it. If I make a web project without master pages I simply put in the head...
2
by: news.sbcglobal.net | last post by:
I hope I can explain this well enough to understand. I have a master page that is used by almost all of the pages in my site. On the master page is a table. In one of the cells in this table, I...
7
by: xkeops | last post by:
Thinking of creating a website, most of the pages will have a general toolbar menu, a content and a footer. The content will be the only one who's gonna change but the rest (header,footer) will...
2
by: Argirop | last post by:
I have a page Default.aspx. Its first line is the following: <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="default.aspx.cs"...
3
by: Rich | last post by:
Hi, I want to use 2 master pages, one for the main part of the site, the other for the admin pages. They are quite similar, with many shared elements. Ideally I would like to have a parent...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.