473,385 Members | 1,944 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,385 software developers and data experts.

Master Pages - moving controls in code behind?

I'm running into a problem with Master Pages.

I have some "absolute" controls (labels, textboxes) that I position on the
page using:

ControlObject.Style.Add("Top", "250")

or

ControlObject.Style.Add("Left", "100")

regardless of what value I use, the controls are always being placed at
0,0 -- any suggestions? This method worked fine when I was not using Master
Pages, but when I converted over to Master Pages this no longer works.

Thanks, Rob.
Jun 6 '06 #1
1 1808
We can't reference controls directly when used with Master Pages. We have to
reference controls used with Master Pages using a public Property or the
FindControl method. You need to find articles and learn how Master Pages are
actually compiled into the page to really understand whats going on. This is
a must-do. For now...

Its fairly easy to use FindControl when the control is in the .master itself
but when the control is located in a content page and the controls are
templated "finding" a control using FindControl can become frustrating.

I've included a couple of URLs [1,2] to help you get started and my own
little trick which uses trace enabled in the content page to locate the
control when the control is located in templates making it easy to use
FindControl.

// Enable trace in the content page and locate the control named
"CreateUserButton"

// ctl00$InnerPanelContent$CreateUserWizard$__CustomN av2$CreateUserButton

// Use FindControl on each control in the path of the control tree hierarchy
Button createUserButton =
(Button)Page.Master.FindControl("InnerPanelContent ").FindControl("CreateUserWizard").FindControl("__ CustomNav2").FindControl("CreateUserButton");

// Now we can directly reference the control
createUserButton.Text = "Button Text";

There's got to be better way but I haven't figured it out yet and the
articles I've read don't say much about the context of controls when deeply
nested in templates.

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/
[1] http://msdn2.microsoft.com/en-us/lib...f0(vs.80).aspx
[2] http://www.odetocode.com/Articles/450.aspx

"Rob R. Ainscough" <ro*****@pacbell.net> wrote in message
news:O3**************@TK2MSFTNGP04.phx.gbl...
I'm running into a problem with Master Pages.

I have some "absolute" controls (labels, textboxes) that I position on the
page using:

ControlObject.Style.Add("Top", "250")

or

ControlObject.Style.Add("Left", "100")

regardless of what value I use, the controls are always being placed at
0,0 -- any suggestions? This method worked fine when I was not using
Master Pages, but when I converted over to Master Pages this no longer
works.

Thanks, Rob.

Jun 6 '06 #2

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

Similar topics

2
by: Learner | last post by:
Hello, This is first time I have started using Master Pages. I am using ASP.NET 2.0 (VB) in Visual Studion 2005. This is how I am doing it... I have created a master page and placed a...
17
by: Rob R. Ainscough | last post by:
Again another simple concept that appears NOT to be intuitive or I'm just stupid. I've read the WROX book and the example doesn't actually show how the .master page links in the other content...
0
by: Learner | last post by:
Hello, We use Master Pages in our website and need a page to be created dynamically. I am not sure where I am missing but I don't see any error and the controls on the page either! Here is my...
3
by: sqlboy2000 | last post by:
Hi, I've just started playing around with master / detail pages and I'm trying to simply change the detail page displayed in the contentplaceholder control from code behind. I can't seem to find...
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: ...
3
by: William Youngman | last post by:
I am on a team that is developing a proposal generation web application and we are using a custom base page (ProGenBase.cs) located in the app_code directory and all of the app's web pages inherit...
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...
0
by: dixonjm | last post by:
Hi, I have a master page & various pages that will use this master page. Each content page will have a CSS & JS file which will be named the same as the content page. When I try to load the CSS...
10
by: Cirene | last post by:
I know that sometimes referring to controls deep in a page using a Master Page can be funky. For a website using a standard header/footer/nav, do you prefer using User Controls for the common...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.