0

I am new to .net web forms programming (also my first time posting on here) and I am trying to get the title of a page from another class called session.

From each code behind page for each of my content pages, I am calling a method that is in a Session class. I am trying to update the code so that under certain circumstances, I can get the page title of the page that called the method in the Session class. However, I don't want to have to update all the code behind files calling the class (there are a lot) to send the page instance as a parameter in the method. Is there a way I could get the Page instance of the class that called the method from inside the Session class instead? I can get the Url of the page using HttpContext.current.Request.Url.AbsoluteUri so I was hoping I could use something similar to get the page or the title, or that I can use the url to get the page or title.

When I googled this everything I am finding is for if you already have the page instance and have been unable to find a way to actually get that page instance or title.

Note: The Session class is written using C#.

Thanks

mkolf3
  • 1
  • 3

1 Answers1

0

The TITLE is just content, and can change at any time, without warning, even by the user. I recommend updating 'all my pages :(' to pass the title, or the entire object.

Just remember, soon you'll ask the question "no no, how do I find out what it REALLY is? not what it's meant to be" and then you'll have to do the same 'all my pages :(' plumbing, but this time in javascript!

Davesoft
  • 724
  • 1
  • 4
  • 10
  • Thank you very much for the response back. I actually ended up figuring out I can use HttpContext.Current.CurrentHandler to get the page and then Title from there. I got this from the following post https://stackoverflow.com/questions/2495194/access-current-instance-of-page-from-a-static-class. I was struggling with my issue at hand for a while so thanks again for the added information. My case is a bit of an exception but I will have to consider updating on all the pages now. Thanks! – mkolf3 Jul 02 '18 at 19:16