How to access controls on another aspx page

J

~john

If I have a label on the Master Page that I would like to change its
text with a button on one of the content pages, Default.aspx... It's
giving me an error saying "Label1" is not found. Can you only find
controls on the current page.. ie Default.aspx.cs can only access
controls on the Default.aspx page?

~john
 
B

bruce barker \(sqlwork.com\)

the correct way is to have the master page implement an interface (defined
in app_code), for accessing its controls for which you need to create public
properties. then you can cast this.Master to. the cheap way is to include
<%@ MasterType %> directive on the page, then just use this.Master t
accessing any controls that you have created public properties for.


-- bruce (sqlwork.com)
 
J

Jan Kucera

Or you could use Master.FindControl().
Jan

bruce barker (sqlwork.com) said:
the correct way is to have the master page implement an interface (defined
in app_code), for accessing its controls for which you need to create
public properties. then you can cast this.Master to. the cheap way is to
include <%@ MasterType %> directive on the page, then just use this.Master
t accessing any controls that you have created public properties for.


-- bruce (sqlwork.com)
 
M

Mark Rae

If I have a label on the Master Page that I would like to change its
text with a button on one of the content pages, Default.aspx... It's
giving me an error saying "Label1" is not found. Can you only find
controls on the current page.. ie Default.aspx.cs can only access
controls on the Default.aspx page?

((Label)Master.FindControl("Label1")).Text = "Hello";

But Bruce Barker's suggestion is probably more robust...
 
M

master_programmer

An easy solution to this problem is to create an IFrame within your
page, thus exposing the target page within the IFrame. The you can
click buttons on the other page from your parent page.

The Master
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top