Beginner question: Changing contentplaceholder on button click

Please support our ASP.NET advertiser: Intel Parallel Studio Home
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

Re: Beginner question: Changing contentplaceholder on button click

 
0
  #11
Aug 25th, 2008
Originally Posted by greeny_1984 View Post
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.
Ok, I was trying to do this without simply posting everything, but here it is. As I'm just starting out in web development (with a hobbyist mentality) I'm keeping everything very basic right now, just trying to lay down the framework to start.

My masterfile contains 3 main DIV sections, a header, the main content, and a footer. Things are being organized with a stylesheet which I don't think needs to be posted.

MasterPage.master
  1. <%@ Master Language="C#"
  2. AutoEventWireup="true"
  3. CodeFile="MasterPage.master.cs"
  4. Inherits="MasterPage" %>
  5.  
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7.  
  8. <html xmlns="http://www.w3.org/1999/xhtml">
  9. <head id="MasterHead" runat="server">
  10. <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
  11. </head>
  12.  
  13. <body>
  14. <form id="MasterPageForm" runat="server">
  15.  
  16. <div id="master_header">
  17. <div id="master_headertop">
  18. <asp:Image runat="server" ID="HeaderImage"
  19. ImageUrl="~/Images/logo.GIF"
  20. </div>
  21. <div id="master_headerbottom">
  22. <asp:Button ID="btnHome" runat="server" Text="Home" Width="150"
  23. onclick="btnHome_Click" ></asp:Button>
  24.  
  25. <asp:Button ID="btnPage1" runat="server" Text="Page1" Width="150"
  26. onclick="btnPage1_Click"></asp:Button>
  27.  
  28. <asp:Button ID="btnPage2" runat="server" Text="Page2" Width="150"
  29. onclick="btnPage2k"></asp:Button>
  30.  
  31. <asp:Button ID="btnPage3" runat="server" Text="Page3" Width="150"
  32. onclick="btnPage3"></asp:Button>
  33.  
  34. <asp:Button ID="btnPage4" runat="server" Text="Page4" Width="150"
  35. onclick="btnPage4"></asp:Button>
  36.  
  37. <asp:Button ID="btnPage5" runat="server" Text="Page5" Width="150"
  38. onclick="btnPage5"></asp:Button>
  39. </div>
  40. </div>
  41.  
  42. <div id="master_content" runat="server">
  43. <div id="master_contentplaceholder">
  44. <asp:ContentPlaceHolder id="mainContent" runat="server">
  45. <H1>HOME</H1>
  46. </asp:ContentPlaceHolder>
  47. </div>
  48. </div>
  49. <div id="master_footer">
  50. /*...Footer stuff*/
  51. </div>
  52. </form>
  53. </body>
  54. </html>

Here's the current C# code for the master page, where I'm trying to implement the button functionality. The button_click function is the default setup by Visual Studios.

MasterPage.Master.CS
  1. public partial class MasterPage : System.Web.UI.MasterPage
  2. {
  3.  
  4.  
  5. protected void Page_Load(object sender, EventArgs e)
  6. {
  7. }
  8.  
  9. protected void btnHome_Click(object sender, EventArgs e)
  10. {
  11. }
  12.  
  13. protected void btnPage1_Click(object sender, EventArgs e)
  14. {
  15. //Isn't working
  16. Content con = new Content();
  17.  
  18. con = (Content)Master.FindControl("~/Page1.aspx").FindControl("content1");
  19. masterplaceholder.ID = con.ContentPlaceHolderID;
  20. }
  21.  
  22. protected void btnPage2_Click(object sender, EventArgs e)
  23. {
  24. }
  25.  
  26. protected void btnPage3_Click(object sender, EventArgs e)
  27. {
  28. }
  29.  
  30. protected void btnPage4_Click(object sender, EventArgs e)
  31. {
  32. }
  33.  
  34. protected void btnPage5_Click(object sender, EventArgs e)
  35. {
  36. }
  37.  
  38. }

And here's the corresponding .aspx files. I only need to show one, as there's nothing in them at the moment except some text to display which page is loading. The .aspx files are named "Page1.aspx" to "Page5.aspx", and the content ID "content1" to "content5".

page1-5.aspx
  1. <%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
  2. AutoEventWireup="true" CodeFile="Page1.aspx.cs" Inherits="Page1" %>
  3.  
  4. <asp:Content ID="content1" ContentPlaceHolderID="mainContent" runat="server">
  5. <h1>PAGE 1</h1>
  6. </asp:Content>

So what I want to do is fairly simple. I want the content of Page#.aspx loaded into the MainContent placeholder section of the Master Page when one of the buttons in the Master Header is clicked.
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
  #12
Aug 27th, 2008
is the master file different for all the pages or is the same as have given in u r question
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
  #13
Aug 28th, 2008
Originally Posted by greeny_1984 View Post
is the master file different for all the pages or is the same as have given in u r question
It's the same, I only have one master file right now. One master file to many pages, I thought that's how it worked?
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,080
Reputation: SheSaidImaPregy is an unknown quantity at this point 
Solved Threads: 68
SheSaidImaPregy SheSaidImaPregy is offline Offline
Veteran Poster

Re: Beginner question: Changing contentplaceholder on button click

 
0
  #14
Aug 28th, 2008
What you are doing should be referenced by each page. When you click a button in your header, which is located on your master page, you want the main content to change? This is done by just going to the next page, that references the master. This is still a server call, so it's exactly as going to the next page.

So, with your master page created, now create your content pages that just reference the contentplaceholder from the master, which is the control asp:Content.

It is it's own separate page, so you just go from page to page, where your master will stay the same. You do this by setting your master in the head line of the document. It will do the rest itself.

However, with your header as a contentplaceholder, if you have buttons in them, you will have to either copy the code to each page you use with that header, or just make the header part of the master page.

Does this make sense?

The master page will be standard among all pages that reference it, or among all pages if hard-coded into the web.config file.

Then each page that has the content just references the master page and only place the content in the appropriate content holders. Any code not within those holders will throw an error.
I answer pm's.
I answer questions.
I answer quickly.
I answer.
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
  #15
Aug 29th, 2008
hi,
there is no need to load pages in contentplaceholder of master file,u cant debug master page.if u want to achieve the functioanlity ,u can create a usercontrol containing
the linkbuttons u have used in the master page.
just create a placeholder in the master page and load the user control in to it.

and debug page1.aspx.
u can achieve the functionality u want
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