views:

67

answers:

3
+1  Q: 

Master Page

I need to ask if I have master page that contain button as an example then I add new webform(default) and I assign that master page as default form master page.the question is can I change the text of the button in default page code?

+1  A: 

I would use a property on the master page to change the button, I think you can make it public but meh.

public String ButtonText { get { return button1.text; } set { button1.Text = value } }

Then on the default page, set the master type.

<%@ MasterType VirtualPath="~/mymaster.master"  %>

Then on the default page you should be able to access by going through the property.

Master.ButtonText = "Hello, Master Page Button";

[Sorry, assuming C#]

Joshua Belden
This is a good approach, since it encapsulates the inner implementation of the master pages.
niaher
A: 

If you put the MasterType directive on your default page

<%@ MasterType VirtualPath="~/Master1.master" %>

then you can call methods and properties on the master page in the code-behind:

MyButton.Text = "New text";

For more information see ASP.Net 2.0 - Master Pages: Tips, Tricks, and Traps

BengtBe
+2  A: 

sure you can, it's either way...

you should see the video screencasts about MAster Pages, you will see how to accomplish that and much more!

Video # 12 MasterPages 16 minutes, 2 seconds

Video # 36 How Do I: Work with Master Pages Declaratively and Programmatically 29 minutes, 49 seconds

Video # 37 How Do I: Handle Events in Master and Content Pages 23 minutes, 26 seconds

balexandre
+1 for video links (:
peirix
Glad that you liked... ASP.NET/Learn Website has sooo many videos :) It's a great reference for those you love screencasts, like me ;)
balexandre
I just realized that video 36 and 37 links to the same video. Might wanna fix that :p
peirix
Done! Thanks :)
balexandre