Adding in a small change to the Master Page Page_Load Event

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 лет назад
Hello All!!
I hope everyone is enjoying the snow lol.


I have a small question, that I assume is easy to answer. I added a label control to my root.master page.
I would like to reference this label when the page loads (on ANY page, hence why I added it to root.master)

Thats it.

I tried adding in a public void Page_Load() event to the master page, but it doesnt fire. I assume that there is an override in the codebase behind??

Very simply-
How do I add something to the root.master Page_Load event??

Thank you very much!!!!
13 лет назад
Any ideas?!!!
13 лет назад
I'm not totally sure what you are trying to do, but I assume you want to write to the label in the master page from a child page?

Anyway, if you look in the NopCommerceStore folder and find another folder called Controls, you'll see all the BaseNopPage classes that all the pages inherit from.

Add a method in here, referencing this.master.mylabel (or whatever the syntax is?). You should be able to call that from anywhere in a page, provided it inherits the BaseNopPage class.

Note: I try and avoid labels [because they generate spans] and use literals as much as possible. They reduce markup clutter.
13 лет назад
Hey Ed-

Much obliged for your response!
When you say, add a method, can you elaborate for me please?

I am a noob when it comes to this. This is the only change I need to make to launch our website.

THanks alot!!
13 лет назад
THis is what I did (please correct me if wrong).
In the control / BaseNopMasterPage.cs, I added this to the Page_Load event

               Label UrlLabel = Page.Master.FindControl("URLLabel") as Label;
                  switch (Request.PathInfo.Substring(1))
                {
                    case "product1":
                        UrlLabel.Text = "This is Product1 Image Section";
                        break;
                    case "Product2":
                        Response.Write("This is Product2 Image Section");
                        break;
                    case "Product3":
                        Response.Write("This is Product3 Image Section");
                        break;
                    case "Product4":
                        Response.Write("This is Product4 Image  Section");
                        break;
                    case "Product5":
                        Response.Write("This is Product4 Image  Section");
                        break;
                    default:
                        UrlLabel.Text = "I have failed";
                }

What I am trying to do is when the page loads, read the incoming URL, and change the label text to reflect where they came from.
13 лет назад
anyone?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.