Masterpage and default.aspx

Can I refer to the controls on default.aspx from the masterpage?
I have a form on the masterpage which sends information that is in a
gridview in the default.aspx page.
Jape [ Do, 10 April 2008 14:09 ] [ ID #1939365 ]

RE: Masterpage and default.aspx

Hi,

If you want access control to content page (control, which exists on master
page), then you can access it through like this..

HtmlControl body = (HtmlControl)this.Page.Master.FindControl("Body");

"Jape" wrote:

> Can I refer to the controls on default.aspx from the masterpage?
> I have a form on the masterpage which sends information that is in a
> gridview in the default.aspx page.
UjvalShah [ Do, 10 April 2008 15:51 ] [ ID #1939377 ]

Re: Masterpage and default.aspx

On Apr 10, 9:51 am, Ujval Shah <UjvalS... [at] discussions.microsoft.com>
wrote:
> Hi,
>
> If you want access control to content page (control, which exists on master
> page), then you can access it through like this..
>
> HtmlControl body = (HtmlControl)this.Page.Master.FindControl("Body");
>

I think he wants it the other way round. I.e., in his master page, he
would like to get a reference to a control in a child page of the
master page.
gnewsgroup [ Do, 10 April 2008 18:53 ] [ ID #1939401 ]

Re: Masterpage and default.aspx

Yes, this is what i want.
The gridview is on the contentpage and i want to acess it from the masterpage.

"gnewsgroup" wrote:

> On Apr 10, 9:51 am, Ujval Shah <UjvalS... [at] discussions.microsoft.com>
> wrote:
> > Hi,
> >
> > If you want access control to content page (control, which exists on master
> > page), then you can access it through like this..
> >
> > HtmlControl body = (HtmlControl)this.Page.Master.FindControl("Body");
> >
>
> I think he wants it the other way round. I.e., in his master page, he
> would like to get a reference to a control in a child page of the
> master page.
>
Jape [ Fr, 11 April 2008 11:12 ] [ ID #1940162 ]

Re: Masterpage and default.aspx

Hi Jape,

Given the below markup & code, this may be of help to you:

GridView g = (GridView) myPlaceHolder.FindControl("myDDL");

Site1.master.aspx:

<% [at] Master Language="C#" AutoEventWireup="true"
CodeBehind="Site1.master.cs" Inherits="Site1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="myLabel" />
<asp:ContentPlaceHolder ID="myPlaceHolder" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>

Default.aspx:

<% [at] Page Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="LoginApp._Default"
MasterPageFile="~/Site1.Master"%>

<asp:Content ID="myContent" ContentPlaceHolderID="myPlaceHolder"
Runat="Server">
<asp:DropDownList ID="myDDL" runat="server">
<asp:ListItem Value="1" Text="Indeed" />
<asp:ListItem Value="2" Text="Yeah" />
<asp:ListItem Value="3" Text="Exactly" />
</asp:DropDownList>
</asp:Content>


Site1.master.cs:

using System;
using System.Web.UI;
using System.Web.UI.WebControls.

public partial class Site1 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
GridView g = (GridView) myPlaceHolder.FindControl("myDDL");
}
}

=========
Regards,
Steve
www.stkomp.com

Jape wrote:
> Can I refer to the controls on default.aspx from the masterpage?
> I have a form on the masterpage which sends information that is in a
> gridview in the default.aspx page.
On Apr 11, 11:12 am, Jape <J... [at] discussions.microsoft.com> wrote:
> Yes, this is what i want.
> The gridview is on the contentpage and i want to acess it from the masterpage.
>
> "gnewsgroup" wrote:
> > On Apr 10, 9:51 am, Ujval Shah <UjvalS... [at] discussions.microsoft.com>
> > wrote:
> > > Hi,
>
> > > If you want access control to content page (control, which exists on master
> > > page), then you can access it through like this..
>
> > > HtmlControl body = (HtmlControl)this.Page.Master.FindControl("Body");
>
> > I think he wants it the other way round. I.e., in his master page, he
> > would like to get a reference to a control in a child page of the
> > master page.
wisccal [ Fr, 11 April 2008 15:15 ] [ ID #1940178 ]
Microsoft » microsoft.public.dotnet.framework.aspnet » Masterpage and default.aspx

Vorheriges Thema: NETTIERS
Nächstes Thema: Q: Div tags driving me crazy.