Web Forms :: Access Public Properties Of Master From Content Page?

Mar 9, 2010

Here's the scenario: A class based on System.Web.UI.Page has been created. A number of content pages derive from this class. All of these content pages use the same master page. The content pages define controls which need to access things on the master page (in code-behind). This is fine - no problem. In particular, each content page has its own data grid. The grid on each page has the same name, so that common code can reference it. In fact, some event handling for the grids on each content page is identical, so would like to factor that code to the base class. Interestingly, I can actually define the event handler entirely in the base class, with no stub in the content class at all, because the wire-up of event handlers uses the event-handler name defined in the grid, and that name happens to be found in the inherited base class. All good and dandy... very cool in fact. The problem comes when the code in the base class needs to access any of the common elements from the content page's master. Remember, the master is the same, and I know the type of the master. I would like to do something like this in the base-class code:

((myMasterType)this.Master).PropertyofMaster=xxx;

The problem is, that myMasterType - the type of the master page the content pages are using - is not available at compile time, at least not from a class definition for a base page. I've found articles that claim that the class name of the master is available - and it is, but not from a separate class. I CAN see it and compile with the master's class name from, for example, the code behind of the various content pages. But the actually class simply isn't available, it seems, from a pure class (the base page class). Judging from other times this question has been asked, here are common misunderstandings offered as solutions: 1. Use a page directive to declare the master type. This is not even vaguely a part of the problem, as the issue is not code in the content page, but in a separate base class which content pages inherit from. That base class is a pure class -- no .ASPX file at all. 2. Pass a reference to the master object from the content page to the base class. This can be done, but is pointless, because I can already get it, using "this.Master" from the base class! But because the type of the master is not available at compile time from the base class, it can't be passed from the content page either - unless it is passed with type MasterPage, thus losing all the properties/methods publically defined in the specific master page class. 3. Move the base page class out of the App_Code folder because the app_code folder is compiled before the other classes, and thus before the master page class. Doesn't work -- put the master page class file right in the same folder with these content pages and their master page, and the master page class is still not available at compile time from within the class. Re-summarized: Base page inherited by content pages. Content pages all use a common master page. Want to access the public properties of that master page from the base page, at runtime. Barrier is that I can find no way from within the base class to cast the master page object to the actual master page subclass being used.

View 7 Replies


Similar Messages:

Web Forms :: To Access A Public Property In A Master Page From A  Nested Content Page

Apr 26, 2010

to whom it may concern,

I wish to access a public property in a master page from a nested content page

is there anyway to do that without using "master type"

i found this link

http://www.velocityreviews.com/forums/t110057-accessing-properties-from-nested-master-pages.html

but i dont understand what "companywide" is

((CompanyWide)this.Master.Page.Master).HtmlTitle = "now it is working";

i dont want to use "MasterType" i would rather cast..

View 11 Replies

Web Forms :: Accessing Public Property Inside User Control In Master Page From Content Page

Nov 9, 2010

I have user control in the master page. user control code behind page having public property called SetValue.

Now I want to set the value from content page .

View 4 Replies

Web Forms :: Access Public Function In Master Page?

Sep 5, 2010

I need accessing the function in my masterpage.

I have a.master and b.aspx with the content page.

Now in the page load of my content page, I want to execute the an sql query which is in a function in my master page.

How can I access the function in my master page?

code in my master page:

public function info () as string
'SQL Query
end function

View 7 Replies

Web Forms :: Can Modify The Properties Of A Content Page Control From An Event Fired From The Master Page?

Feb 25, 2011

Can I modify the properties of a content page control from an event fired from the master page?create a delegate and event on master page wire up the master page in the content page create the event handler (function) on the content page modify for example:

contents of the Text property of a textbox render a control visible (or hidden) etc...

View 4 Replies

Web Forms :: Access Public Property Of User Control In Master Page On Child Pages?

Nov 29, 2010

How can one access public property of User Control In Master Page on child Pages.

View 1 Replies

Web Forms :: Hiding Repeater On Master Page From Content Page / Access From Content Page?

Oct 6, 2010

My project has the following repeater menu shown on the Master Page. I need this menu to remain hidden until the user logs in. How do I access from content page?

[Code]....

View 2 Replies

Web Forms :: Can't Access Master Page Properties In Visual Studio?

Oct 8, 2010

I have created a Master Page and exposed a Literal control on it by way of a public property.

[Code]....

In my content page I have referenced the Master Page like so :

[Code]....

However in my content page code behind I cannot see the custom properties of the master page in Visual Studio.

View 5 Replies

C# - Access Master Page Public Method From User Control/class/page

Oct 25, 2010

I am to access a method on my master page. I have an error label which I want to update based on error messages I get from my site.

public string ErrorText
{
get { return this.infoLabel.Text; }
set { this.infoLabel.Text = value; }
}

How can I access this from my user control or classes that I set up?

View 3 Replies

Web Forms :: Master Pages - How To Access Content Page From Master Page

Sep 5, 2010

I have a master page setup that is used throughout my site that is basically a header with a menu. I recently added a textbox and a button to this master page which is to be a quick search box that is available anywhere in the site. When a user enters text into the search box and hits the button, I need to load the actual content page which is used to search and show search results (which also uses this same master page), and have the text entered available so the search can be triggered automatically. Again, this search text box and button is now in my master page so it could be triggered from anywhere in the app... it serves as a convenient way to do a basic search from anywhere in my app, without having to first navigate to the actual 'search page' that already exists. You can also navigate to the actual search page, which uses the same master page, where there is many more search options.I'm thrown off by the master page arrangement, which I have not used until this project. What do I do?

View 4 Replies

How To Access Public Properties

Jun 14, 2010

I have two pages page1.aspx and page2.aspx, both have code behind with partial classes. How do i access public property message on page1.aspx from page2.aspx ?

public string message { get; set; }

View 5 Replies

Best Way To Set Master Page Properties In Content Page?

Sep 1, 2010

There are different ways to set the title for content pages from Master page

by findcontrol by creating property in master page and setting the value in content page

As both method requires an object creation of master page which will be little heavy
myMasterPage myMaster = (myMasterPage)this.Master;

so I have tried it by creating a class and it worked -

public class clsmaster
{
public static clsmaster objmaster = new clsmaster();
public strtitle {get;set;}
}

Now I just need to access this static object and set the property in the content page and in the master page I just need the controls to take the value from this class (clsmaster).

View 2 Replies

Web Forms :: Access User Control Of Master Page In The Content Page

Jan 27, 2010

I have a user control in the master of my website and I want change some property of that control from the content page.

View 3 Replies

Web Forms :: Access Control Declared In Master Page In Content Page

Dec 8, 2012

How to access a control declared in a Master Page in a content page.I have a ModalPopUpExtender in Master Page and i want to access it from a content page, how can i do that.

View 1 Replies

Web Forms :: Access Master Page Method In Child Or Content Page

Feb 13, 2014

I created one method in master page, I want to use that method in some other page(Child or Content page).I tried this method but No luck, it's not working in Master Page:

public partial class TestMaster : System.Web.UI.MasterPage
{
public void XXXX()
{
}
}

I'm trying to call this method in child page like

TestMaster MyMasterPage = (TestMaster )this.Master;
MyMasterPage.

View 1 Replies

Web Forms :: Access Master Page Body In Content Page

Sep 23, 2010

i want to access master page body in content page (code behind)

<body id="pagebody" runat="server"> (master page body)

View 3 Replies

Web Forms :: How To Access Content Page Controls From Master Page

Feb 12, 2011

it is very easy to access master page control from content page like

[code]....

but how could i access controls of content page from master page. suppose a textbox there in content page and one button is there in master page. i want that when i will click on master page button then i want to show the text of textbox in the content page in the label of master page. how to achieve it.

View 1 Replies

Web Forms :: Can't Access A Control In The Master Page From A Content Page

Dec 16, 2010

Does any know why I can't access the my custom user control StatusBar which is declared inside a masterPage?

In the ContentPage, I tried referencing the control this way "this.Site.stastusBar" and "this.Master.Status" and neither one works. Both instellisense warns me that "statusBar" does not exist.

Below is my Aspx code and code-behind:

[code]....

View 3 Replies

Web Forms :: Access Master Page Control Value On Content Page?

Mar 25, 2010

on master page, i have declared a label control & set value to it.now on content page, i m able to find the control, but the value is alwasy null & not the one which was set.when i debugged, content page's load event is called first, after that the master page is called.so where should i access the master page control so that i get the set value.

View 4 Replies

Web Forms :: How To Access Content Page Function From Master Page

Sep 10, 2013

I have a dropdown box in master and i would like to execute the content page function when user select any value from dropdown box.

View 1 Replies

Web Forms :: Access Function In Master File From Content Page?

Jan 12, 2011

I have functions in a Master Page that I want to access in content pages. How do I do that?

View 9 Replies

Web Forms :: Access Master Page Controls In Content Pages?

Dec 17, 2012

Today I got a strange problem,that is I am unable to access master page controls in its code behind,I am wonder because,I can able to access master page controls in their code behind of other projects/applications's master pages.

I know we can acess like this Label lblText = (Label)this.FindControl("lbluserName"); in that situation but I need to access div controls which are set to run at server.

View 1 Replies

How To Access Public Properties Of MasterPage From External Class

Jun 13, 2010

Why i can't access MasterPage's public property (MessagePlaceholder) from other Class (Errors) ?Error compiler gives me is "Error 1 The type or namespace name 'MyMasterPage' could not be found (are you missing a using directive or an assembly reference?)"my master page code behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class MyMasterPage : System.Web.UI.MasterPage
{
public string MessagePlaceholder

[code]...

View 1 Replies

WCF / ASMX :: How To Get Access Public Properties From Webservice Class

Aug 2, 2010

i have websrvice class in this i declared a webmethod and a public property my problem is i want to acess service class public property in my asp.net web application after creating proxy object.

service class:

[Code]....

View 1 Replies

Web Forms :: Access Class Instance Declared On Master From Content Page?

Apr 8, 2010

Can I access a class instance declared on the master page from a content page?

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved