| | |
Beginner question: Changing contentplaceholder on button click
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2008
Posts: 11
Reputation:
Solved Threads: 0
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:
Repeat from content1 to content5 to match 5 buttons.
Now I need to fill in this section (I think):
but am not sure how it's done. Any help would be appreciated, thanks.
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)
<%@ Page Language="C#" MasterPageFile="~/Master.master" AutoEventWireup="true" CodeFile="Content1.aspx.cs" Inherits="Content1" %> <asp:Content ID="content1" ContentPlaceHolderID="content_section" runat="server"> <h1>CONTENT 1</h1> </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)
protected void btnContent1_Click(object sender, EventArgs e) { }
but am not sure how it's done. Any help would be appreciated, thanks.
•
•
Join Date: Jul 2008
Posts: 11
Reputation:
Solved Threads: 0
•
•
•
•
I don't know asp but in javascript it looks something like this.
document.placeholder.src = "hello.gif"
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.
•
•
Join Date: Aug 2008
Posts: 12
Reputation:
Solved Threads: 1
if you are trying to show different content at different times by the click of a button. You could use a <div>..
Example:
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
Example:
asp Syntax (Toggle Plain Text)
<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
•
•
Join Date: Jul 2008
Posts: 11
Reputation:
Solved Threads: 0
•
•
•
•
Hi
could you perhaps give more detail on what you want to achieve?
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)
<%@ Page Language="C#" MasterPageFile="~/EgocentricMaster.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <asp:Content ID="default_content" ContentPlaceHolderID="main_placeholder" runat="Server"> <h1>DEFAULT</h1> </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)
<div id="master_maincontent" runat="server"> <asp:ContentPlaceHolder id="main_placeholder" runat="server"> </asp:ContentPlaceHolder> </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
ASP.NET Syntax (Toggle Plain Text)
if u have five contentplaceholders in u r master page,u can use this to find control of each contentplaceholder ContentPlaceHolder mcon = new ContentPlaceHolder(); mcon = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1"); 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
Live and Let Live
•
•
Join Date: Jul 2008
Posts: 11
Reputation:
Solved Threads: 0
•
•
•
•
ASP.NET Syntax (Toggle Plain Text)
if u have five contentplaceholders in u r master page,u can use this to find control of each contentplaceholder ContentPlaceHolder mcon = new ContentPlaceHolder(); mcon = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1"); u can make visible false for other content placeholders on each button click
ASP.NET Syntax (Toggle Plain Text)
protected void button1_Click(object sender, EventArgs e) { Content con = new Content(); con = (Content)Master.FindControl("~/Page1.aspx").FindControl("content1"); masterplaceholder.ID = con.ContentPlaceHolderID; }
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?
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: how do you properly instantiate an activeX control on aspx
- Next Thread: How to disply all .jpeg images inside a folder in my web page
| Thread Tools | Search this Thread |
.net 2.0 3.5 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn checkbox child click commonfunctions compatible confirmationcodegeneration content contenttype countryselector courier css dataaccesslayer database datagrid datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dropdownmenu edit expose feedback flash flv form formatdecimal forms formview gridview homeedition hosting iframe iis javascript jquery list listbox login menu microsoft mono mouse mssql multistepregistration nameisnotdeclared news numerical objects order panelmasterpagebuttoncontrols radio ratings rotatepage save schoolproject search security serializesmo.table silverlight smartcard sql-server sqlserver2005 suse textbox tracking typeof unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webarchitecture webdevelopemnt webservice xml youareanotmemberofthedebuggerusers





