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