How to change content in MasterPage by clicking a button?

B

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">
<p> This is student page</p>
</asp:Content>

Thank you
Bon
 
G

Guest

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
 
M

Mark Rae

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.
 
B

Bon

Thank you guys.

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

Thanks
 
N

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 said:
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 said:
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.
 
E

Eliyahu Goldin

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# said:
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 said:
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 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top