How to access controls on another aspx page

  • Thread starter Thread starter ~john
  • Start date Start date
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
 
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)
 
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)
 
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...
 
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
 
Back
Top