473,386 Members | 2,042 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,386 software developers and data experts.

multiple asp:content's requires multiple datasources?

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

Similar topics

8
by: John | last post by:
Greetings, I was talking to my host company representative this evening, and he thought that certain web crawlers (he mentioned Offline Explorer /and/ Anawave WebSnake would be able to download...
3
by: robin9876 | last post by:
In an asp.net (VB) web page I have created a HTML table that has some server side labels which has information populated to at runtime from code. This works for when there is only one recorded...
3
by: Gerhard | last post by:
Is it possible to embed a .pdf file inside <asp:Content></asp:Content>? I have a page that has a master page with navigation, etc., and I want the content to be what is in a .pdf file. Is this...
2
by: Victor Rodriguez | last post by:
I need a way to be able to retrieve child controls on a <asp:Content I've try I get nothing. Where should I look? thanks, Vic
4
by: Janto Dreijer | last post by:
Hi! The Nokia Java SDK allows one to define multiple content-types in a single HTTP header field. I'm not sure if it's standard, but it's happening from some Java-enabled phones. This breaks...
3
by: MikeB | last post by:
Hello, I have a content page that is from a Master page which has 2 content panes. How do I add my forms to the content page? Each pane needs a form but you can not have multiple form tags nor...
1
by: Joe Kovac | last post by:
Hi! I use: <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> <link rel="stylesheet" href="../javascript/my.css" /> <script src="../javascript/my.js"...
5
by: fran7 | last post by:
Hi, I have set up a next navigation with this code <% Set NextLink = Server.CreateObject ("MSWC.NextLink") %> <A HREF="<%= NextLink.GetNextURL ("/links.txt") %>">Next Page </A> and a .txt...
1
by: baburk | last post by:
Hi, How to refresh only a particular asp:Content for certain period of time. How can i? <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"> ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.