473,414 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to change content in MasterPage by clicking a button?

Bon
Dear all

I create a master page with image buttons on the left-hand side for
navigation. When a user clicks the student button, the content (i.e.
ContentPlaceholder) in masterpage will be changed from default.aspx to
students.aspx.

I tried to create a subroutine in MasterPage.master.vb to do it. The
code is as following. But, the default.aspx's content is shown in
MasterPage even I clicked the student button.

How can I do that? Please give me some advices.

Here is my code:

MasterPage
=========

<html>
<body>
<form id="MasterForm" runat="server">
<table width="100%" border="0" cellpadding="0" cellspacing="0"
background="images/sidenavbg.gif">
<tr>
<td>
<asp:ImageButton runat="server" ImageUrl="~/Images/btn_students.gif"
width="183" height="26" id="btn_home" />
</td>
</tr>
....
</form>
</body>
</html>

MasterPage.master.vb
================
Partial Class MasterPage
Inherits System.Web.UI.MasterPage

Sub btn_students_click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs)
'Me.btn_students.Attributes.Add("onclick",
"this.src='students.aspx';")
End Sub
End Class

students.aspx
==========
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
AutoEventWireup="false" CodeFile="students.aspx.vb" Inherits="students"
title="testing" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<pThis is student page</p>
</asp:Content>

Thank you
Bon

Dec 25 '06 #1
7 13014
You are using the concept of MasterPages incorrectly by assuming you can set
the "src" property as if it were an HTML IFRAME.
What you want to do is simply load the other page.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"Bon" wrote:
Dear all

I create a master page with image buttons on the left-hand side for
navigation. When a user clicks the student button, the content (i.e.
ContentPlaceholder) in masterpage will be changed from default.aspx to
students.aspx.

I tried to create a subroutine in MasterPage.master.vb to do it. The
code is as following. But, the default.aspx's content is shown in
MasterPage even I clicked the student button.

How can I do that? Please give me some advices.

Here is my code:

MasterPage
=========

<html>
<body>
<form id="MasterForm" runat="server">
<table width="100%" border="0" cellpadding="0" cellspacing="0"
background="images/sidenavbg.gif">
<tr>
<td>
<asp:ImageButton runat="server" ImageUrl="~/Images/btn_students.gif"
width="183" height="26" id="btn_home" />
</td>
</tr>
....
</form>
</body>
</html>

MasterPage.master.vb
================
Partial Class MasterPage
Inherits System.Web.UI.MasterPage

Sub btn_students_click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs)
'Me.btn_students.Attributes.Add("onclick",
"this.src='students.aspx';")
End Sub
End Class

students.aspx
==========
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
AutoEventWireup="false" CodeFile="students.aspx.vb" Inherits="students"
title="testing" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<pThis is student page</p>
</asp:Content>

Thank you
Bon

Dec 25 '06 #2
"Bon" <bo***********@gmail.comwrote in message
news:11*********************@h40g2000cwb.googlegro ups.com...
How can I do that? Please give me some advices.
You're doing this backwards! As Peter said, the ContentPlaceHolder in a
MasterPage is not the same as the source of a frame - that's not how it
works at all.

Let's say you have two pages, default.aspx and students.aspx, both of which
are ContentPages.

When your app starts, it loads default.aspx which, being a ContentPage,
merges itself with its MasterPage and streams down to the client.

It has a button / hyperlink / linkbutton / whatever control on it which,
when clicked, simply redirects to students.aspx - you could do this
server-side with Response.Redirect, or client-side with window.location

This loads student.aspx which, being a ContentPage, merges itself with its
MasterPage and streams down to the client.

You need to read a beginner's guide to MasterPages.

The best way to start is to understand that the MasterPage isn't actually a
page object at all - it's a Control object - the ContentPage integrates it
just like it would integrate any other Control object.
Dec 25 '06 #3
Scatt Allen has a good article for understanding master pages:
http://www.odetocode.com/Articles/450.aspx

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:u%****************@TK2MSFTNGP03.phx.gbl...
"Bon" <bo***********@gmail.comwrote in message
news:11*********************@h40g2000cwb.googlegro ups.com...
>How can I do that? Please give me some advices.

You're doing this backwards! As Peter said, the ContentPlaceHolder in a
MasterPage is not the same as the source of a frame - that's not how it
works at all.

Let's say you have two pages, default.aspx and students.aspx, both of
which are ContentPages.

When your app starts, it loads default.aspx which, being a ContentPage,
merges itself with its MasterPage and streams down to the client.

It has a button / hyperlink / linkbutton / whatever control on it which,
when clicked, simply redirects to students.aspx - you could do this
server-side with Response.Redirect, or client-side with window.location

This loads student.aspx which, being a ContentPage, merges itself with its
MasterPage and streams down to the client.

You need to read a beginner's guide to MasterPages.

The best way to start is to understand that the MasterPage isn't actually
a page object at all - it's a Control object - the ContentPage integrates
it just like it would integrate any other Control object.

Dec 25 '06 #4
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:u%******************@TK2MSFTNGP02.phx.gbl...
Scatt Allen
Doo bee doo bee doo bop...

Sorry, couldn't resist... ;-)
Dec 25 '06 #5
Bon
Thank you guys.

I am newbie on ASP .NET. I thought MasterPage is like iframe. I will
read the article.

Thanks

Mark Rae wrote:
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:u%******************@TK2MSFTNGP02.phx.gbl...
Scatt Allen

Doo bee doo bee doo bop...

Sorry, couldn't resist... ;-)
Dec 26 '06 #6
n#
So what master page actually does is keeps the compile time code
structured @ the cost of run time over load.

Assume I have a left hand menu (which gets populate from a datasource),
header & a iframe to populate the contents.

So now with the advent of master page, everytime the menu has to be
rendered with the actual content page. I don't see a big advantage in
this.

Eliyahu Goldin wrote:
Scatt Allen has a good article for understanding master pages:
http://www.odetocode.com/Articles/450.aspx

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:u%****************@TK2MSFTNGP03.phx.gbl...
"Bon" <bo***********@gmail.comwrote in message
news:11*********************@h40g2000cwb.googlegro ups.com...
How can I do that? Please give me some advices.
You're doing this backwards! As Peter said, the ContentPlaceHolder in a
MasterPage is not the same as the source of a frame - that's not how it
works at all.

Let's say you have two pages, default.aspx and students.aspx, both of
which are ContentPages.

When your app starts, it loads default.aspx which, being a ContentPage,
merges itself with its MasterPage and streams down to the client.

It has a button / hyperlink / linkbutton / whatever control on it which,
when clicked, simply redirects to students.aspx - you could do this
server-side with Response.Redirect, or client-side with window.location

This loads student.aspx which, being a ContentPage, merges itself with its
MasterPage and streams down to the client.

You need to read a beginner's guide to MasterPages.

The best way to start is to understand that the MasterPage isn't actually
a page object at all - it's a Control object - the ContentPage integrates
it just like it would integrate any other Control object.
Dec 26 '06 #7
As I replied to you in another thread, in this particular case there is no
reason to switch to master pages.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"n#" <ks*******@gmail.comwrote in message
news:11**********************@i12g2000cwa.googlegr oups.com...
So what master page actually does is keeps the compile time code
structured @ the cost of run time over load.

Assume I have a left hand menu (which gets populate from a datasource),
header & a iframe to populate the contents.

So now with the advent of master page, everytime the menu has to be
rendered with the actual content page. I don't see a big advantage in
this.

Eliyahu Goldin wrote:
>Scatt Allen has a good article for understanding master pages:
http://www.odetocode.com/Articles/450.aspx

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:u%****************@TK2MSFTNGP03.phx.gbl...
"Bon" <bo***********@gmail.comwrote in message
news:11*********************@h40g2000cwb.googlegro ups.com...

How can I do that? Please give me some advices.

You're doing this backwards! As Peter said, the ContentPlaceHolder in a
MasterPage is not the same as the source of a frame - that's not how it
works at all.

Let's say you have two pages, default.aspx and students.aspx, both of
which are ContentPages.

When your app starts, it loads default.aspx which, being a ContentPage,
merges itself with its MasterPage and streams down to the client.

It has a button / hyperlink / linkbutton / whatever control on it
which,
when clicked, simply redirects to students.aspx - you could do this
server-side with Response.Redirect, or client-side with window.location

This loads student.aspx which, being a ContentPage, merges itself with
its
MasterPage and streams down to the client.

You need to read a beginner's guide to MasterPages.

The best way to start is to understand that the MasterPage isn't
actually
a page object at all - it's a Control object - the ContentPage
integrates
it just like it would integrate any other Control object.

Dec 26 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Federico | last post by:
I have a problem, I have an event declared in a Master Page, and I want to use in a Content Page holder of a Content Page. When I want to create the method to handle the event, I can njot reference...
2
by: Rob Roberts | last post by:
In a VS2005 ASP.NET project, I'm trying to find a way to change which css file is linked in based on the browser type. I'd like to use one css file for IE browsers, and a different one for all...
0
by: Adam Tibi | last post by:
Hello, I have this: MasterPage 1: <asp:ContentPlaceHolder ID="cphHead" runat="server"> </asp:ContentPlaceHolder> Some Html... <asp:ContentPlaceHolder ID="cphBody1" runat="server">...
9
by: ad | last post by:
Hi, How can I dynamically change the MasterPager of a web page?
5
by: visu | last post by:
Hi this is a question asked in this group two years back.. No answer for this question till date. now i am in the same situation of the questioner.. to find a solution for this problem. Can any...
1
by: =?Utf-8?B?am9uZWZlcg==?= | last post by:
I keep getting the message after I converted a regular aspx page to now be based on a master page: "Only Content controls are allowed directly in a content page that contains Content controls."...
7
by: John | last post by:
Hi there, I have a CSS based menu in a master page that uses class attributes to determine which item is currently selected. So, for example if the Homepage is currently the active page then...
0
by: e_spork | last post by:
I am using Page.ClientScript.RegisterStartupScript to throw up a Javascript alert box. When I click OK on the alert box, all the controls on my page disappear and I don't understand why. I can...
5
by: Murray | last post by:
Forgive me if this question is too basic, but I'm new to ASP.NET programming, and I can't locate a simple answer to this question. I have a web page that consists of a Master Page and a single...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.