943,879 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 9898
  • ASP.NET RSS
You are currently viewing page 1 of this multi-page discussion thread
Aug 15th, 2008
0

Beginner question: Changing contentplaceholder on button click

Expand Post »
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:

ASP.NET Syntax (Toggle Plain Text)
  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):
ASP.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RandV80 is offline Offline
13 posts
since Jul 2008
Aug 17th, 2008
0

Re: Beginner question: Changing contentplaceholder on button click

I don't know asp but in javascript it looks something like this.
document.placeholder.src = "hello.gif"
Reputation Points: 40
Solved Threads: 7
Junior Poster
architact is offline Offline
114 posts
since Apr 2008
Aug 17th, 2008
0

Re: Beginner question: Changing contentplaceholder on button click

Click to Expand / Collapse  Quote originally posted by architact ...
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RandV80 is offline Offline
13 posts
since Jul 2008
Aug 19th, 2008
0

Re: Beginner question: Changing contentplaceholder on button click

Hi

could you perhaps give more detail on what you want to achieve?
Reputation Points: 10
Solved Threads: 1
Newbie Poster
bheeks is offline Offline
12 posts
since Aug 2008
Aug 19th, 2008
0

Re: Beginner question: Changing contentplaceholder on button click

if you are trying to show different content at different times by the click of a button. You could use a <div>..
Example:

asp Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
bheeks is offline Offline
12 posts
since Aug 2008
Aug 21st, 2008
0

Re: Beginner question: Changing contentplaceholder on button click

Click to Expand / Collapse  Quote originally posted by bheeks ...
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:

ASP.NET Syntax (Toggle Plain Text)
  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:

ASP.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RandV80 is offline Offline
13 posts
since Jul 2008
Aug 22nd, 2008
0

Re: Beginner question: Changing contentplaceholder on button click

ASP.NET Syntax (Toggle Plain Text)
  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
Reputation Points: 25
Solved Threads: 29
Posting Whiz
greeny_1984 is offline Offline
372 posts
since Apr 2007
Aug 22nd, 2008
0

Re: Beginner question: Changing contentplaceholder on button click

u can use tab container control in ajaxcontroltoolkit ,if u are using ajax
Reputation Points: 25
Solved Threads: 29
Posting Whiz
greeny_1984 is offline Offline
372 posts
since Apr 2007
Aug 23rd, 2008
0

Re: Beginner question: Changing contentplaceholder on button click

ASP.NET Syntax (Toggle Plain Text)
  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:

ASP.NET Syntax (Toggle Plain Text)
  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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
RandV80 is offline Offline
13 posts
since Jul 2008
Aug 25th, 2008
0

Re: Beginner question: Changing contentplaceholder on button click

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.
Reputation Points: 25
Solved Threads: 29
Posting Whiz
greeny_1984 is offline Offline
372 posts
since Apr 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: how do you properly instantiate an activeX control on aspx
Next Thread in ASP.NET Forum Timeline: How to disply all .jpeg images inside a folder in my web page





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC