Master page - cannot add controls

G

Guest

Hi,
I'm a newbie to master pages & have added images dragged from my image
folder directly to a master page. This image is available to all forms that
use this master page.
However, if I add an image control, a frame or layer object to my master
page, then save & build, these don't show up on my forms, nor does anything
in them.

Is this expected behaviour or am I misundertanding the way a master page
should be used?

many thanks for any help here

Ant
 
K

Kevin Spencer

A MasterPage is used in an ASP.Net Page to provide content that is common to
any Page that employs (or hosts) it. It is employed via the @Page tag in the
hosting Page, as in the following example:

<%@ Page Language="C#" Inherits="Default" CodeFile="Default.aspx.cs"
masterpagefile="MainPage.master"
title="Example" AutoEventWireup="true"%>

Once the MasterPage is hosted in a Page, the contents of the Page will be
the contents of the MasterPage when it is requested via HTTP by a browser.

The MasterPage may also have ContentPlaceHolder Controls in it, which allow
any Page hosting it to add additional Controls and HTML content inside the
bounds of the Control. In the MasterPage, a ContentPlaceHolder looks like
this:

<asp:ContentPlaceHolder id="MainContentPlaceHolder" runat="server">
</asp:ContentPlaceHolder>

In the hosting Page, the reference to the ContentPlaceHolder looks like
this:

<asp:Content id="Content1" runat="server"
contentplaceholderid="MainContentPlaceHolder">
<!-- Here is where the additional Page-specific content belongs -->
</asp:Content>

Now, from your description, I can't tell what you're doing. For example, you
say that "the image is available to all forms that use this master page."
What do you mean by "available?" And what do you mean by "these don't show
up on my forms, nor does anything in them?" Where do they not show up? In
your development environment? In the code for the pages? In a browser?

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 
M

Mark Rae [MVP]

Now, from your description, I can't tell what you're doing.

The OP is placing controls *inside* the <asp:ContentPlaceHolder /> tag on
the MasterPage instead of the <asp:Content /> tag on the content page...
 
G

Guest

Hi Mark,

I don't know what happened but it's all fine now. I just started from
scratch & now no issues. Before, whenever I changed content on the master
Page after associating it with web pages, the changes wouldn't show up on the
web page unless I chose "Default to Master Content" but then I would lose all
the local content I added, unless I chose "Choose Custom content", so it was
either one or the other (?). Additionally, it was rendering button controls
right across the screen.
There must have been something wrong with that initial Master page 'build'.
As you noted, it was not adding controls into content placeholder in the
markup when it should have.

Anyway, alls well that end well...

P.S It's a great tool. I'm sold!
 
M

Mark Rae [MVP]

As you noted, it was not adding controls into content placeholder in the
markup when it should have.

In fact, it's the other way round... You had placed controls *inside* your
<asp:ContentPlaceHolder> tag when you shouldn't, because they will get
overwritten when the page builds itself...
 
G

Guest

Hi Mark,

Thanks for the reply; the odd thing is though that I hadn't touched the
Markup at all. It had all been done from the UI, so I don't know how it could
have happened.
but anyway...

Thanks

Ant
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top