Click here to Skip to main content
14,735,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i have two master pages
one is for all the site users(main.master) and
other is for admin(admin.master)

now my problem is, i want to change the text of a label in main.master from admin's home page.

I have used the following code on button click:
((Label)(Master.FindControl("Label37"))).Text = TextBox20.Text;

it works fine but it changes label in admin.master and not in main.master as i hv used admin.master for admin's home page.

how to find control from a specific master page?


The code you have updates the admin.master because it is being invoked at runtime, main.master is not being processed by the ASP.NET engine at the time your code is being executed so it is not in the context of the code being executed.
These types of dynamic configurations are usually persisted in a database and processed at runtime to dynamically modify the page as required. As it is now the even the change you are making must be reapplied each time, correct? when you reload the page the change is not there is it?
A page can have only one master page, so you cannot change a master page's content from another master page. You should read a good article to understand how master pages work. To do what you are trying to do, you must store your information in a application variable or cache or database (or any location that can be accessed by administrators and other users) and then read the information in the main master page.
patelKhyati 18-Aug-11 10:41am
i know very well how a master page works. you are not getting my question.I have clearly mentioned that i have two master pages one belongs to the admin and other is for users. Now whatever the changes i make takes place in the admins master page and not in the users master page. what i want actually is to make changes in the user master page and not in admin. i have used the following
((Label)(Master.FindControl("Label37"))).Text = TextBox20.Text; now i wanted to know how can i make this work for the master page i want to make changes.
Now are you able to understand what m trying to say?
[no name] 18-Aug-11 15:09pm
If you know how a master page works, you wouldn't be asking this question.

Ok, let me put it in this way. If you wish to make changes in the user's master page, you must execute the code in the user master page's code behind.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900