Click here to Skip to main content
15,918,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

i have a class and i must make all pages inherite from it ,
i dont want to make each page inherite from a class
is there is a way to make all pages inherite from this class in one step ???

Thanks

Posted

1 solution

Have this in your web config file

XML
<configuration>
  <system.Web>
    <pages masterPageFile="your master name.master" />
  </system.Web>
</configuration>


the
XML
<system.web></system.web>
tag may be already exists, then only need to add the pages tag inside of it. Don't define a new System.Web tag

The above one is for .Net framework 4, some of the lower version may have this syntax
XML
<pages master="your master.master"></pages>


Can have a master page inherited from a class inherited from master page.

In case of all the pages has to use a common base class, alternatively can have a class with extension methods for the Page class.

Example...

C#
public static class PageExtensionMethods
{
    public static string GetDefaultCopyRightString(this Page globalPage)
    {
        return "Copy Right Reserved Test Company , 2011";
    }
}



Now you can call this method from any page i.e in all pages..example..

C#
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       string copyRight=this.GetDefaultCopyRightString();
    }
}
 
Share this answer
 
v6
Comments
Hercal 19-Feb-11 18:12pm    
but where is the class i want to inheriteFrom ?????
Hercal 19-Feb-11 18:18pm    
You understand Me >>????
I have Class called Say (BasePage) i want all my pages .aspx inherite from this Class
Exaple : Default Page .aspx


public partial class _Default : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{

}
}

Understand me ?????
I want to make this Step on all my Pages in one Step

Thankx man 4 your Effort
Albin Abel 19-Feb-11 23:55pm    
I m not sure that is possible. All those pages by default inherited from the page class. If you want some functions globally available for the page class, you can try extension methods for the page class. I improved the answer as per your question
Hercal 21-Feb-11 1:10am    
Thanx man for your effort

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900