By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,718 Members | 1,840 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,718 IT Pros & Developers. It's quick & easy.

Master Pages - moving controls in code behind?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.