473,382 Members | 1,078 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,382 software developers and data experts.

How to Update or Change the Master Page Variables from a different Page?

I'm developing a shopping cart. I've assigned some Session values to
Labels on the Master Page. The Basket panel which is small window for
the basket items will be visible on every page if there are any items
in the basket. It will display Total Quantity and Total Price in that
window. The Master Page code shown below

protected void Page_Load(object sender, EventArgs e)
{
if (Convert.ToString(Session["Total"]) != string.Empty)
{
pllogin.Visible = false;
plbasket.Visible = true;
lblquantity.Text = Convert.ToString(Session["TotQty"]);
lblprice.Text = Convert.ToString(Session["Total"]);
}
}

Hope i made myself clear till now.
In the basket Page , i'm calculating the total Price and Quantity and
storing them in Sessions as shown below
Session["Total"] = GetProductTotal();
Session["TotQty"] = intQty;
So, basically on the basket page when i press the Update button I want
the Master page values to get updated and be displayed in the small
window which is not happening straight away, So I need to refresh the
page to get it updated, which is not what i want.
Should I be using any classes (.cs) outside the page ?
Is there anyway to get over this problem ?
Am i going in the right directions ?
Thanks for your help and time in Advance

Jun 5 '06 #1
8 2178
"savvy" <jo******@gmail.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
Should I be using any classes (.cs) outside the page ?
No need.
Is there anyway to get over this problem ?
Yes.
Am i going in the right directions ?


Sort of...

Let's say you have a master file called secure.master with an associated
partial class called master_secure.

public partial class master_secure : System.Web.UI.MasterPage
{
public Label MyLabel;
}

To refer to the label from a content placeholder, you would do the
following:

((master_secure)Master).MyLabel.Text = "Hello world";
Jun 5 '06 #2
Thank you very much Mark for your time and help
I tried to do this
public partial class Home1 : System.Web.UI.MasterPage
{
public Label lblqty;
}

and on the other page if i'm trying to assign the lblqty as
protected void Page_Load(object sender, EventArgs e)
{
((Home1)Master).lblqty.Text = "Hello World";
}
its giving an error message saying
Object reference not set to an instance of an object.
i'm not able to understand where the problem lies
Can you help, Thanks

Jun 5 '06 #3
savvy wrote:
Thank you very much Mark for your time and help
I tried to do this
public partial class Home1 : System.Web.UI.MasterPage
{
public Label lblqty;
} Should be:

public Label lblqty = new Label();

and on the other page if i'm trying to assign the lblqty as
protected void Page_Load(object sender, EventArgs e)
{
((Home1)Master).lblqty.Text = "Hello World";
}
its giving an error message saying
Object reference not set to an instance of an object.
i'm not able to understand where the problem lies
Can you help, Thanks

Jun 5 '06 #4
Thank you very very much mates
I'm really greatful to u lot
That worked perfectly and was a perfect solution to my problem
thanks once again
Ray Booysen wrote:
savvy wrote:
Thank you very much Mark for your time and help
I tried to do this
public partial class Home1 : System.Web.UI.MasterPage
{
public Label lblqty;
}

Should be:

public Label lblqty = new Label();

and on the other page if i'm trying to assign the lblqty as
protected void Page_Load(object sender, EventArgs e)
{
((Home1)Master).lblqty.Text = "Hello World";
}
its giving an error message saying
Object reference not set to an instance of an object.
i'm not able to understand where the problem lies
Can you help, Thanks


Jun 5 '06 #5
"Ray Booysen" <rj***********@rjb.za.net> wrote in message
news:us**************@TK2MSFTNGP03.phx.gbl...
savvy wrote:
Thank you very much Mark for your time and help
I tried to do this
public partial class Home1 : System.Web.UI.MasterPage
{
public Label lblqty;
}
Should be:

public Label lblqty = new Label();


Correct - apologies, my reply was from memory, and I should have actually
tested it first...
Jun 5 '06 #6
Better yet so you don't have to cast your master page each time for
access in your pages' code behinds, add the following to the .aspx
file. (You can also set in the web config for all pages in a site, but
I do not like to do this in case you wish for a page not to use the
master.)

<%@ MasterType TypeName="Base_master" %>

where Base_master is the name of the master page code behind you are
trying to reference.

You can then access public properties and methods from the master in
the page using it.

In the master:

string m_JobTitle;
public string Job
{
get { return m_JobTitle; }
set { m_JobTitle= value;}
}

In your .aspx.cs

Master.JobTitle= "Professional Hack";

Regards
Coleman

Jun 6 '06 #7
<mi**************@gmail.com> wrote in message
news:11**********************@h76g2000cwa.googlegr oups.com...

And even better than that, make "Base_master" a separate class which
inherits MasterPage and derive all your master pages from that...
Better yet so you don't have to cast your master page each time for
access in your pages' code behinds, add the following to the .aspx
file. (You can also set in the web config for all pages in a site, but
I do not like to do this in case you wish for a page not to use the
master.)

<%@ MasterType TypeName="Base_master" %>

where Base_master is the name of the master page code behind you are
trying to reference.

You can then access public properties and methods from the master in
the page using it.

In the master:

string m_JobTitle;
public string Job
{
get { return m_JobTitle; }
set { m_JobTitle= value;}
}

In your .aspx.cs

Master.JobTitle= "Professional Hack";

Regards
Coleman

Jun 6 '06 #8
Thanks Micheal,
I followed the approach you gave
that perfectly fitted the bill
i had some problems with my previous approach
I got some more info from this link as well
http://www.odetocode.com/Articles/450.aspx
Thank you very much to all for your help and time
mi**************@gmail.com wrote:
Better yet so you don't have to cast your master page each time for
access in your pages' code behinds, add the following to the .aspx
file. (You can also set in the web config for all pages in a site, but
I do not like to do this in case you wish for a page not to use the
master.)

<%@ MasterType TypeName="Base_master" %>

where Base_master is the name of the master page code behind you are
trying to reference.

You can then access public properties and methods from the master in
the page using it.

In the master:

string m_JobTitle;
public string Job
{
get { return m_JobTitle; }
set { m_JobTitle= value;}
}

In your .aspx.cs

Master.JobTitle= "Professional Hack";

Regards
Coleman


Jun 7 '06 #9

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

Similar topics

17
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
1
by: BigSam | last post by:
I have updated my master page to reflect some different formatting. When I open one of the pages that uses the master page, the change isn't reflected. How do I tell the child page the master has...
3
by: Roy | last post by:
Hi Access gurus, I have a A2K application.The data in the database is updated daily by a excel download.I have a master n related tables keyed in by a OrderID.I have a problem in updating data.If...
1
by: LilC | last post by:
I'm creating an application that has a standard layout for all pages. The information that is displayed in the layout will be dynamic based on the user that is logged in. Thus when a page is...
4
by: David Lozzi | last post by:
Howdy, I have my master page, and I would like to change the background CSS class per the content page. Only the home page has a different background style, all other pages are using the same. I...
0
by: Managed Code | last post by:
Hello All, Here is my issue and thanks in advance for any assistance. I have a base page with a dropdownlist that fires an event with the selected index. The content page catches the event and...
10
by: _Who | last post by:
Seems to me that I should be able to do something like: ....runat="server" change from white.css to black.css... Of course if I could have found out how, I wouldn't be bothering you. Is...
3
prasans
by: prasans | last post by:
I have stored some of the variables used by lot of other pages of my website on the master page. As we are migrating to a load balanced environment, I want to know if I need to move those variables...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.