dynamically change contentpage in MasterPage ???

Discussion in 'ASP .Net' started by Chris, Feb 21, 2010.

  1. Chris

    Chris Guest

    hello.

    How can I dynamically change a contentpage of the masterpage?

    I have a listbox in the masterpage. Depending on the selected item i
    want to show a different contentpage.

    I try something like this (masterpage-code)

    protected void DropDownList1_SelectedIndexChanged(object sender,
    EventArgs e)
    {
    switch (somethingtoTest)
    {
    case "1": ContentPlaceHolder1.Page = "Page1.aspx";
    break;

    case "2": ContentPlaceHolder1.Page = "Page2.aspx";
    break;
    break;
    }
    }

    But the code is not accepted since "ContentPlaceHolder1.Page" is not
    of type string.

    But how then?

    thank you
    Chris
     
    Chris, Feb 21, 2010
    #1
    1. Advertising

  2. "Chris" <> wrote in message
    news:...
    > hello.
    >
    > How can I dynamically change a contentpage of the masterpage?
    >
    > I have a listbox in the masterpage. Depending on the selected item i
    > want to show a different contentpage.
    >
    > I try something like this (masterpage-code)
    >
    > protected void DropDownList1_SelectedIndexChanged(object sender,
    > EventArgs e)
    > {
    > switch (somethingtoTest)
    > {
    > case "1": ContentPlaceHolder1.Page = "Page1.aspx";
    > break;
    >
    > case "2": ContentPlaceHolder1.Page = "Page2.aspx";
    > break;
    > break;
    > }
    > }
    >
    > But the code is not accepted since "ContentPlaceHolder1.Page" is not
    > of type string.
    >
    > But how then?


    What a master page is, really, is a user control on a page. It does not
    appear so due to the way it works, but that is what it is. As such, you
    cannot get there from here. You can kludge up the page change, but you would
    be better to add a postback to the dropdownlist and then have it redirect to
    the correct page.

    --
    Peace and Grace,
    Greg

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    ************************************************
    | Think outside the box! |
    ************************************************
     
    Gregory A. Beamer, Feb 21, 2010
    #2
    1. Advertising

  3. Chris

    Chris Guest

    On Feb 21, 3:34 am, "Gregory A. Beamer"
    <> wrote:
    > "Chris" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > hello.

    >
    > > How can I dynamically change a contentpage of the masterpage?

    >
    > > I have a listbox in the masterpage. Depending on the selected item i
    > > want to show a different contentpage.

    >
    > > I try something like this (masterpage-code)

    >
    > >  protected void DropDownList1_SelectedIndexChanged(object sender,
    > > EventArgs e)
    > >    {
    > >          switch (somethingtoTest)
    > >          {
    > >              case "1": ContentPlaceHolder1.Page = "Page1.aspx";
    > > break;

    >
    > >              case "2": ContentPlaceHolder1.Page = "Page2.aspx";
    > > break;
    > >                  break;
    > >          }
    > >    }

    >
    > > But the code is not accepted since "ContentPlaceHolder1.Page" is not
    > > of type string.

    >
    > > But how then?

    >
    > What a master page is, really, is a user control on a page. It does not
    > appear so due to the way it works, but that is what it is. As such, you
    > cannot get there from here. You can kludge up the page change, but you would
    > be better to add a postback to the dropdownlist and then have it redirect to
    > the correct page.
    >
    > --
    > Peace and Grace,
    > Greg
    >
    > Twitter: @gbworld
    > Blog:http://gregorybeamer.spaces.live.com
    >
    > ************************************************
    > |    Think outside the box!                        |
    > ************************************************


    Hello.

    >"but you would be better to add a postback to the dropdownlist and then have it redirect to
    > the correct page."


    I don't understand. I'd say a master page consists of, amongst other
    things, a contextplacehoder,
    Contextplacehoder you use to display content of a page, hence the Page-
    property of contextplacehoder.

    how would you implement it then?
    could you give me some sample code please?

    thank you
    Chris
     
    Chris, Feb 21, 2010
    #3
    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. Replies:
    1
    Views:
    504
    Scott Allen
    Nov 22, 2005
  2. User
    Replies:
    9
    Views:
    10,445
  3. dawg1998
    Replies:
    2
    Views:
    3,624
    zehramb
    May 31, 2010
  4. =?Utf-8?B?ZGF3ZzE5OTg=?=
    Replies:
    0
    Views:
    489
    =?Utf-8?B?ZGF3ZzE5OTg=?=
    Mar 15, 2006
  5. Replies:
    7
    Views:
    13,183
    TuckWong
    Jan 11, 2013
Loading...

Share This Page