Masterpage and default.aspx

Discussion in 'ASP .Net' started by Jape, Apr 10, 2008.

  1. Jape

    Jape Guest

    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, Apr 10, 2008
    #1
    1. Advertising

  2. Jape

    Ujval Shah Guest

    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.
     
    Ujval Shah, Apr 10, 2008
    #2
    1. Advertising

  3. Jape

    gnewsgroup Guest

    On Apr 10, 9:51 am, Ujval Shah <>
    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, Apr 10, 2008
    #3
  4. Jape

    Jape Guest

    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 <>
    > 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, Apr 11, 2008
    #4
  5. Jape

    Guest

    Hi Jape,

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

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

    Site1.master.aspx:

    <%@ 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:

    <%@ 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 <> 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 <>
    > > 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.
     
    , Apr 11, 2008
    #5
  6. Jape

    jaya Guest

    Can I refer to the controls on default.aspx from the masterpage?


    > On Thursday, April 10, 2008 8:09 AM Jap 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 Thursday, April 10, 2008 9:51 AM UjvalSha 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");
    >>
    >> "Jape" wrote:



    >>> On Friday, April 11, 2008 5:12 AM Jap 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 Saturday, April 12, 2008 7:23 AM gnewsgroup wrote:


    >>>> wrote:
    >>>>
    >>>> 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.



    >>>>> On Saturday, April 12, 2008 7:23 AM wiscca wrote:


    >>>>> Hi Jape,
    >>>>>
    >>>>> Given the below markup & code, this may be of help to you:
    >>>>>
    >>>>> GridView g = (GridView) myPlaceHolder.FindControl("myDDL");
    >>>>>
    >>>>> Site1.master.aspx:
    >>>>>
    >>>>> <%@ 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:
    >>>>>
    >>>>> <%@ 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:
    >>>>> On Apr 11, 11:12 am, Jape <> wrote:



    >>>>> Submitted via EggHeadCafe
    >>>>> .NET Windows Services - Timer, Debugging, and Installation
    >>>>> http://www.eggheadcafe.com/tutorial...rvices--timer-debugging-and-installation.aspx
     
    jaya, Mar 9, 2011
    #6
  7. Jape

    jaya Guest

    jaya, Mar 9, 2011
    #7
  8. Jape

    jaya Guest

    i create a masterpage in masterpage 3 button are there.
    each button repesent one default.aspx
    and each default.aspx contain some controls and coding
    my question is?
    were to write a coding for each default.aspx and using some control weather in contentplaceholder

    Please give the sample coding for?

    > On Thursday, April 10, 2008 8:09 AM Jap 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 Thursday, April 10, 2008 9:51 AM UjvalSha 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");
    >>
    >> "Jape" wrote:



    >>> On Friday, April 11, 2008 5:12 AM Jap 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 Saturday, April 12, 2008 7:23 AM gnewsgroup wrote:


    >>>> wrote:
    >>>>
    >>>> 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.



    >>>>> On Saturday, April 12, 2008 7:23 AM wiscca wrote:


    >>>>> Hi Jape,
    >>>>>
    >>>>> Given the below markup & code, this may be of help to you:
    >>>>>
    >>>>> GridView g = (GridView) myPlaceHolder.FindControl("myDDL");
    >>>>>
    >>>>> Site1.master.aspx:
    >>>>>
    >>>>> <%@ 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:
    >>>>>
    >>>>> <%@ 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:
    >>>>> On Apr 11, 11:12 am, Jape <> wrote:



    >>>>>> On Wednesday, March 09, 2011 5:01 AM jaya wrote:


    >>>>>> Can I refer to the controls on default.aspx from the masterpage?



    >>>>>>> On Wednesday, March 09, 2011 5:02 AM jaya wrote:


    >>>>>>> Can I refer to the controls on default.aspx from the masterpage?



    >>>>>>> Submitted via EggHeadCafe
    >>>>>>> Pass Values Between Windows Forms
    >>>>>>> http://www.eggheadcafe.com/tutorial...bb36f2/pass-values-between-windows-forms.aspx
     
    jaya, Mar 9, 2011
    #8
  9. Jape

    jaya Guest

    Re: Re: Masterpage and default.aspx

    create a masterpage in masterpage 3 button are there.

    each button repesent one default.aspx

    and each default.aspx contain some controls and coding

    my question is?

    were to write a coding for each default.aspx and using some control weather in contentplaceholder



    Please give the sample coding for?

    Submitted via EggHeadCafe
    C# Dynamic XElement wrapper
    http://www.eggheadcafe.com/tutorial...-bda9b6fc8d47/c-dynamic-xelement-wrapper.aspx
     
    jaya, Mar 9, 2011
    #9
  10. Jape

    Brian Cryer Guest

    "jaya" <> wrote in message
    news:...
    > Can I refer to the controls on default.aspx from the masterpage?


    If you are asking a question then its better to start your own thread then
    doing it by repling to a 3 year old thread. By replying to something this
    old its less likely that anyone will notice.

    In a page built using a master page you can refer to controls on the master
    page. From the master page you cannot refer to controls on the page which
    uses it. However, you could define events on the master page which you could
    then implement in your default.aspx page and probably achieve the effect you
    want that way.

    Hope this helps.
    --
    Brian Cryer
    http://www.cryer.co.uk/brian
     
    Brian Cryer, Mar 10, 2011
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    MasterPage -> Page -> MasterPage Code Access

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, Apr 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    7,947
    Steven Cheng[MSFT]
    Apr 14, 2006
  2. ThunderMusic
    Replies:
    2
    Views:
    473
    Gregory Gadow
    Sep 27, 2006
  3. Randy Smith
    Replies:
    9
    Views:
    464
    Mark Rae
    Apr 14, 2007
  4. Steve Kershaw
    Replies:
    2
    Views:
    402
    Mark Rae
    May 17, 2007
  5. tgr0ss
    Replies:
    2
    Views:
    430
    Kumaran Sundar
    Nov 13, 2007
Loading...

Share This Page