473,809 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(objec t sender, EventArgs e)
{
if (Convert.ToStri ng(Session["Total"]) != string.Empty)
{
pllogin.Visible = false;
plbasket.Visibl e = true;
lblquantity.Tex t = Convert.ToStrin g(Session["TotQty"]);
lblprice.Text = Convert.ToStrin g(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 2203
"savvy" <jo******@gmail .com> wrote in message
news:11******** **************@ c74g2000cwc.goo glegroups.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.M asterPage
{
public Label MyLabel;
}

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

((master_secure )Master).MyLabe l.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.M asterPage
{
public Label lblqty;
}

and on the other page if i'm trying to assign the lblqty as
protected void Page_Load(objec t 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.M asterPage
{
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(objec t 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.M asterPage
{
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(objec t 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******** ******@TK2MSFTN GP03.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.M asterPage
{
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 = "Profession al Hack";

Regards
Coleman

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

And even better than that, make "Base_maste r" 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 = "Profession al 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 = "Profession al 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
5033
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 cust_no, ded_type_cd, chk_no)
1
1038
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 been updated? Or have I gone gone awry with something else? Thanks in advance
3
2342
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 it is a one to one update,i face no problem as I update every fields.But let's say if there is a master record with ID and three corresponding related entries for this on day 1.But on the next day,there was a change on related records 2 & 3 but...
1
2951
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 browsed to, I need to check to see if the user has logged in or not. Then if they have logged in, I need to pull their information from the database to display in the header. In previous applications, I made use of a base web page that all the...
4
3141
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 know I can create a new master page, but I'd like to just change the master page from the content page if possible. thanks!
0
2119
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 sets a connection string to the database. The content page has a simple gridview that should show records from the selected database. Initial content page displays data from correct place. first change of dropdownlist correctly updates content...
10
1873
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 something like that possible, so that I can let the users select the color scheme they like?
3
3207
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 to a different place to make them still available even if the requests sent a different web server every time. Had similar problems when I stored these variables in the session object and had to turn on SQLState to make them available in all web...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10640
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10120
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.