Beginner question: Changing contentplaceholder on button click

Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Jul 2008
Posts: 11
Reputation: RandV80 is an unknown quantity at this point 
Solved Threads: 0
RandV80 RandV80 is offline Offline
Newbie Poster

Beginner question: Changing contentplaceholder on button click

 
0
  #1
Aug 15th, 2008
Hi, I'm a decent programmer but am completely new to the Web Development side of things, and am kind of winging it to build a website. I'm using Visual Studios 2008/ASP.net/C#.

So basically, I'm keeping things simple at the moment. I have a master file that contains a 'header', 'content', and 'footer' section. In the header section I have a row of buttons, which when clicked should change the contents of the 'content' section. I have a corresponding .aspx file for each of these, with generic contents to start:

  1. <%@ Page Language="C#" MasterPageFile="~/Master.master"
  2. AutoEventWireup="true" CodeFile="Content1.aspx.cs" Inherits="Content1" %>
  3.  
  4. <asp:Content ID="content1" ContentPlaceHolderID="content_section" runat="server">
  5. <h1>CONTENT 1</h1>
  6. </asp:Content>

Repeat from content1 to content5 to match 5 buttons.

Now I need to fill in this section (I think):
  1. protected void btnContent1_Click(object sender, EventArgs e)
  2. {
  3.  
  4. }

but am not sure how it's done. Any help would be appreciated, thanks.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 109
Reputation: architact is an unknown quantity at this point 
Solved Threads: 7
architact's Avatar
architact architact is offline Offline
Junior Poster

Re: Beginner question: Changing contentplaceholder on button click

 
0
  #2
Aug 17th, 2008
I don't know asp but in javascript it looks something like this.
document.placeholder.src = "hello.gif"
If you think we fight for money and you fight for honor, then remember everyone fights for the thing they don't have...
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 11
Reputation: RandV80 is an unknown quantity at this point 
Solved Threads: 0
RandV80 RandV80 is offline Offline
Newbie Poster

Re: Beginner question: Changing contentplaceholder on button click

 
0
  #3
Aug 17th, 2008
Originally Posted by architact View Post
I don't know asp but in javascript it looks something like this.
document.placeholder.src = "hello.gif"
Thanks for the suggestion, but yeah it isn't quite the same. I can access my placeholder within the code, typing "content_section." brings up a list of functions, but there's no .src or .source, and ones like .page or .id return a value rather than set it.

Browsing around some more any examples I've found online focus on using LinkButton objects combined with a Sitemap within the .aspx file to change the place holder. I haven't been able to translate this into using a regular Button's event handling.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 12
Reputation: bheeks is an unknown quantity at this point 
Solved Threads: 1
bheeks bheeks is offline Offline
Newbie Poster

Re: Beginner question: Changing contentplaceholder on button click

 
0
  #4
Aug 19th, 2008
Hi

could you perhaps give more detail on what you want to achieve?
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 12
Reputation: bheeks is an unknown quantity at this point 
Solved Threads: 1
bheeks bheeks is offline Offline
Newbie Poster

Re: Beginner question: Changing contentplaceholder on button click

 
0
  #5
Aug 19th, 2008
if you are trying to show different content at different times by the click of a button. You could use a <div>..
Example:

  1. <div id="myContent" runat="server"></div>


Once creating the <div> and setting it's "runat" property to "server" you can call the div from within the code behind, you can set the visible property to true or false as well, and you could dynamically create controls within it
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 11
Reputation: RandV80 is an unknown quantity at this point 
Solved Threads: 0
RandV80 RandV80 is offline Offline
Newbie Poster

Re: Beginner question: Changing contentplaceholder on button click

 
0
  #6
Aug 21st, 2008
Originally Posted by bheeks View Post
Hi

could you perhaps give more detail on what you want to achieve?
Sorry, got a little off track, but I'm getting back to this problem now. Part of the problem is I want to do it how architact suggested, something like:

on button# click
placeholder.src = "page#.aspx"

But the ASP placeholder object doesn't work like this, rather it seems to be backwards, the content placeholder is assigned to "page#.aspx" instead? This is my default.aspx file, separate from my master file:

  1. <%@ Page Language="C#" MasterPageFile="~/EgocentricMaster.master" AutoEventWireup="true"
  2. CodeFile="Default.aspx.cs" Inherits="_Default" %>
  3.  
  4. <asp:Content ID="default_content" ContentPlaceHolderID="main_placeholder" runat="Server">
  5. <h1>DEFAULT</h1>
  6. </asp:Content>

I have several .aspx files set up like this at the moment. Which I want to swap in and out of the main content section. Which looks like this in my master file at the moment:

  1. <div id="master_maincontent" runat="server">
  2. <asp:ContentPlaceHolder id="main_placeholder" runat="server">
  3. </asp:ContentPlaceHolder>
  4. </div>

Using daniweb.com for an example, what I'm trying to accomplish is the "HOME|FORUMS|TUTORIALS|CODE SNIPPETS|BLOGS|LINK DIRECTORY" part of the header. The header always stays the same but when you click on one of the options the content below changes. Except instead of using an ASP:LinkButton type which they seem to use I want to do this with the standard ASP:Button, programmatically.

Maybe this isn't a good idea and I should just stick with LinkButton's?
Last edited by peter_budo; Aug 31st, 2008 at 2:07 pm. Reason: Corecting closing tag
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: Beginner question: Changing contentplaceholder on button click

 
0
  #7
Aug 22nd, 2008
  1.  
  2. if u have five contentplaceholders in u r master page,u can use this to find control of each contentplaceholder
  3. ContentPlaceHolder mcon = new ContentPlaceHolder();
  4. mcon = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
  5. u can make visible false for other content placeholders on each button click
If u r query is achieved,mark the thread as solved

Live and Let Live
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: Beginner question: Changing contentplaceholder on button click

 
0
  #8
Aug 22nd, 2008
u can use tab container control in ajaxcontroltoolkit ,if u are using ajax
If u r query is achieved,mark the thread as solved

Live and Let Live
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 11
Reputation: RandV80 is an unknown quantity at this point 
Solved Threads: 0
RandV80 RandV80 is offline Offline
Newbie Poster

Re: Beginner question: Changing contentplaceholder on button click

 
0
  #9
Aug 23rd, 2008
Originally Posted by greeny_1984 View Post
  1.  
  2. if u have five contentplaceholders in u r master page,u can use this to find control of each contentplaceholder
  3. ContentPlaceHolder mcon = new ContentPlaceHolder();
  4. mcon = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
  5. u can make visible false for other content placeholders on each button click
That's just about it. I only have one "ContentPlaceHolder" actually, and five "Content" objects each in their own .aspx file. These are what I want to swap in and out of the placeholder on a button click. Using your code sample, I came up with:

  1.  
  2. protected void button1_Click(object sender, EventArgs e)
  3. {
  4. Content con = new Content();
  5.  
  6. con = (Content)Master.FindControl("~/Page1.aspx").FindControl("content1");
  7. masterplaceholder.ID = con.ContentPlaceHolderID;
  8. }

I think this should work, but I'm getting a Null Object reference on "content1". This object is listed in the code example of my first post. If I keep working at it I can probably get it myself, but I'm heading out for the day so I'll leave the question up here.

I'm also wondering if I shouldn't be referencing the content in Page1.aspx directly rather than creating an extra variable for it?
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 370
Reputation: greeny_1984 is an unknown quantity at this point 
Solved Threads: 29
greeny_1984's Avatar
greeny_1984 greeny_1984 is offline Offline
Posting Whiz

Re: Beginner question: Changing contentplaceholder on button click

 
0
  #10
Aug 25th, 2008
what u want u want to change the content of the page page.aspx .whats the meaning of content(),can u post u r code here.
If u r query is achieved,mark the thread as solved

Live and Let Live
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC