Last post Jan 18, 2014 08:58 PM by akhilrajau
Jan 17, 2014 11:04 PM|akhilrajau|LINK
I have some confusions in overriding methods. For single area access. I have control some functions in base page. So that the base page is inherited in all pages.
Q1 : Is it necessary to add base.Method() in all overrides.?
I have the following methods in my base page
public class BasePage : System.Web.UI.Page
protected override void OnLoad(EventArgs e)
string strPreviousPage = "";
if (Request.UrlReferrer != null)
strPreviousPage = Request.UrlReferrer.Segments[Request.UrlReferrer.Segments.Length - 1];
if (strPreviousPage == "")
protected override void InitializeCulture()
if (Session["Language"] != null && Session["Language"] is string)
Thread.CurrentThread.CurrentUICulture = new CultureInfo(Session["Language"].ToString());
Here OnLoad event i override so that in all sub pages it will call. But i read some articles that if i remove base.OnLoad(e); from the override method, there is some problems. But in the Cultureinitialize override i didn't called base.IntitializeCulture().
Ofcourse it automatically came and i removed it. But i din't face any problem to update the culture.
Can anyone guide for this. So is it necessary to add base.Method() or this is need in OnLoad() like some situations only?
Q2. If i have 200 pages i need to inherit this base page to inherit the base functions. But if i create a base page for Master Page? because all my sub pages are derived from master page so instead of inheriting all 200 pages i just inherit the base page
to master page so that all can override the base fuctions. Is it good approach? But there is no CultureOverride() method if i create a class with MasterPage inhert.
Can anyone give the correct approach and why?
Jan 18, 2014 06:34 AM|DarrellNorton|LINK
The reason you don't need to add the base call to InitializeCulture is because the method in the base class is empty, as shown in the documentation here: http://msdn.microsoft.com/en-us/library/system.web.ui.page.initializeculture(v=vs.110).aspx
The InitializeCulture method contains no coding logic. Control developers extending the functionality of the Page class
can override the InitializeCulture method to initialize the Culture and UICulture information
for the page.
In the pages that inherit from your base page, if they extended the logic you have in InitializeCulture then you probably would want them to call base.whatever().
You can have a base page class that all pages inherit from. Setting the MasterPage on these Pages, though, is not the same thing as inheriting from them. The hookup of the "Masterpage" property creates an association between the Base Page and the MasterPage
and renders content inside of a specific structure. MasterPages have a base of UserControl, while Pages have a base of TemplateControl. Slightly different.
In short, you can inherit from a Page base class and set those inherited pages to have a common custom MasterPage class you develop.
Jan 18, 2014 08:58 PM|akhilrajau|LINK
k got thanks