By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,078 Members | 1,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,078 IT Pros & Developers. It's quick & easy.

multiple asp:content's requires multiple datasources?

P: n/a
Hi guys

Just a general query regarding using the AccessDataSource within a website
which uses a MasterPage.

The layout of my content page is as follows...

<asp:Content ID="Content1" ContentPlaceHolderID="cphContent" Runat="Server">
<h1><asp:Label runat="server" Text='<%# Eval("StoryTitle") %>"
ID="lblHeading" />
</h1>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="cphSidebar" Runat="Server">
<!-- more Evals and content -->

<!-- data access -->
<asp:AccessDataSource ID="adsStory" runat="server"
DataFile="~/App_Data/data.mdb"
SelectCommand="SELECT [StoryTitle] FROM [Stories]
WHERE ([StoryID] = ?)">
<SelectParameters>
<asp:QueryStringParameter Type="Int32"
QueryStringField="id" />
</SelectParameters>
</asp:AccessDataSource>
</asp:Content>

The problem is that in order to make the databinding work in Content1, I
actually have to create a seperate AccessDataSource object WITHIN Content1.
If I put the AccessDataSource outside the content(s), VS won't compile it.

The only way round is, as I say, to either create 2 datasources (one for
each content), which surely will impact on the level of database activity,
speed, etc? Or alternatively, to use code-behind databinding.

The obvious answer is "just use code-behind") but I feel like I'm missing
something... surely there is a way to have multiple content areas on a
MasterPage child and only use 1 datasource across both? (while still being
able to do it without code-behind) ..?

Thanks

Dan
Feb 19 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi,

Unfortunately the Master Page and the Content Page will not be able to
access each other's control directly. You will have to use FindControl (and
probably need to use it recursively) to access control on the other part.
For DataSourceID data binding to work, the data source control must exist
either in the same naming container as the data listing control that
references it, or in a parent control of the data listing control:

#BaseDataList.DataSourceID Property (System.Web.UI.WebControls)
http://msdn2.microsoft.com/en-us/lib...rols.basedatal
ist.datasourceid.aspx

For controls inside a master page and a content page, they're in different
container. Turn on "Trace" of your master page to see the control tree.

Therefore, I'm afraid you will have to resort back to the code-behind
workaround.

Hope this helps.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Feb 20 '07 #2

P: n/a
Sorry, I was replying too quick.

A few corrections to my previous reply:

1) "Trace" option is only available in your content page.

2) The data source control could be placed on your master page and you can
use it in your content page using DataSourceID; but not vice-versa.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 20 '07 #3

P: n/a
Hi Walter,

Thanks for the explanation - I think I'm with you. Just to clarify...

1) to use a datasource within 2 containers (asp:content's), I have to do
that via code in the code-behind.

2) Alternatively, I could place the datasource in the masterpage and it
would be accessible by both asp:content containers through the control tree?
(the problem there is that I only want the datasource on 1 page, not every
page which uses the master page!)

Makes more sense now, thanks!

Dan

"Walter Wang [MSFT]" wrote:
Sorry, I was replying too quick.

A few corrections to my previous reply:

1) "Trace" option is only available in your content page.

2) The data source control could be placed on your master page and you can
use it in your content page using DataSourceID; but not vice-versa.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 20 '07 #4

P: n/a
Hi Dan,

1) If you put a data source control in your content page, you will have to
use code-behind to bind it to a control which resides in your master page.
See the trace output to learn the control tree hierarchy and read the
documentation of DataSourceID for more information.

2) If you put a data source control on your master page, yes every content
page that is using this master page will be able to use that data source
control's ID in ASPX to bind the data source. However, I don't think this
is a problem if you only need it only on one content page and the master
page.
Please feel free to let me know if you need anything else.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 21 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.