473,387 Members | 1,463 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Control inside content page to access Master Page Vars

HI,

I have a control on a content page that I need to access and modify a
MasterPage variable.

I can find the control alright:

if (Parent.Page.Master.FindControl("Adserver_TopBanne r1") !=
null)
{

}

But I cannot figure out how to cast it so I can change the MasterPage
vars.

Any help would be greatly appreciated.

Thanks!
Jun 27 '08 #1
2 1301
When I had to manipulate variables on the master page I simply created
properties to do it. Every once in a while did the master page load
correctly that I could just use the straight intellisense, but most of
the time I had to do it like this which does make it more
understandable.

MyMasterPage mmp = (MyMasterPage)this.Master;
mmp.MyProperty = "value";

Within the property code you could have it set the control's data to
what you want, or even make the property a method instead.
Jun 27 '08 #2
Hi,

What type of control is it? Suppose it's a Label:

Label banner = (Label)
Parent.Page.Master.FindControl("Adserver_TopBanner 1");

If you don't know the type, there is no need for a cast, but you will
only be able to access the properties and methods that the Control
class defines.

On the other hand, what Christian suggested is also a good option. In
your master page, you could define a property as:

public string MyProperty {
get {
return Adserver_TopBanner1.Text;
}
set {
this.Adserver_TopBanner1.Text = value;
}
}

And then, you can access it as suggested in the above post.

============
Regards,
Steve
www.stkomp.com

Poofactory wrote:
HI,

I have a control on a content page that I need to access and modify a
MasterPage variable.

I can find the control alright:

if (Parent.Page.Master.FindControl("Adserver_TopBanne r1") !=
null)
{

}

But I cannot figure out how to cast it so I can change the MasterPage
vars.

Any help would be greatly appreciated.

Thanks!
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mark | last post by:
I am rephrasing a question from yesterday. I have a page with several user controls : nav, header, and footer currently. What I would like to do is add a new control ('content') and use it like...
10
by: George G. | last post by:
Hi there, I am busy writing a new asp.net application and I am reusing some of my existing asp functions and methods in a user control. I need access to session, request and response in some of...
5
by: Siva | last post by:
Hello I have a dropdownlist inside the gridview as a template column defined as follows: <asp:TemplateField HeaderText="Choose Location"> <ItemTemplate> <asp:DropDownList ID="ddlChooseLoc"...
3
by: ivanpais | last post by:
Hi, I have a Web User Control, Lets say "Foo.ascx", that contains a button "btnFoo". I have a Master Page "Bar.master", that has a label "lblBar". This label is exposed by a public property...
4
by: Boris Yeltsin | last post by:
OK, on my Master Page I have a control: <a id="hypTabAccount" href="#" runat="server">Account</a> Now, in the code-behind (Root.master.vb) I can refer to it simply thus: ...
2
by: Paras | last post by:
Hi, I have 3 ContentPlaceHolders in the MasterPage. In the 2nd content I have placed a usercontrol which has anchor link. This loads another page (without changing loading the content of...
2
by: Stratum | last post by:
It's an old question, and I apologize for raising it again. I use ImageButton objects on my ASP.Net master page to navigate to content pages. For each button, I have two images. One image shows...
4
by: Torben Laursen | last post by:
I want to change the label of a component that I have on a masterpage but I cannot get my hands on it I have a mastepage MP2 that has a button called B2 masterpage MP2 uses masterpage MP1 that has...
5
by: =?Utf-8?B?bXVzb3NkZXY=?= | last post by:
Hi guys I'm trying to make my code as streamlined as possible, and add CSS file references dynamically when they are required, for example, if a page contains a webcontrol, then the related CSS...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.