0

All: I'm new at C#, lifelong VB coder. I'm trying to do something in ASP.NET that I commonly do: Inherit System.Web.UI.Page. I've created the class for the 'InheritedPage', and now I'm pointing my web page to it like this. In VB, the 'load' code in the inherited page runs automatically (before the web page 'load') In C#, it appears that I have to actually call the 'load'. Can you confirm that I'm doing this correctly?

namespace Vendor
{
    public partial class Vendor : InheritedPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                //do I need this?
                InheritedPage_Load(sender, e);

                //more code here

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}

Inherit class

namespace Vendor
{
    public class InheritedPage : System.Web.UI.Page
    {
        public void InheritedPage_Load(object sender, EventArgs e)
        {
            //how do i get this to run automatically?
            Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
            Response.Cache.SetNoStore();

        }
    }
}
3
  • Overwrite "OnLoadComplete" method. Commented May 15, 2024 at 13:27
  • @UweKeim *override Commented May 15, 2024 at 14:01
  • Your try..catch...throw ex block should be removed altogether or at least use throw; instead of throw ex;. Commented May 15, 2024 at 15:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.