I am using two Different master page in my site. On one master page i am using a LoginStatus control. So wanna access that LoginStatus control from other. I have no great knowledge about how to find the controls from one master page to other.
Is there any way to achieving this. Any help is deeply appreciated.
Thanks.
Well if there is single master page and content page you can access control using
Label lblinMaster = (Label)This.Master.FindControl("Label1");
and the same way to access control in nested master page you can use following.
Label lblinParentMaster = (Label)Master.Master.FindControl("Label1");
Hope this helps.
Unless you are using nested master pages, you cannot access one master page from another.
A Page would normally use only one master page at a time.
The users login status, however is not dependent on the LoginStatus control.
You can show this status everywhere.
Refer: ASP.NET Login Controls to get an idea about the right control to use.
Related
I have a button on a Master page and when it is clicked it calls a method on the master page which requires several parameters. The values for the parameters are stored in text boxes and drop down lists on both the master page and the content page. I can get the values from the controls on the master page, but I am not sure how to retrieve the values from the controls on the content page.
I have spent the last day looking at various answers on here and on other sites, but have nor found a solution that works for me.
I have also seen answers that suggest putting the buttons on the control page, but that would mean duplicating code on at least 12 pages and I really dont want to have to go down that route unless I have to.
I forgot to say that I am already using the Master reference tag in the content page.
EDIT
If I create a class and set values in the content page, what would be the best way to retrieve the values in the master page. Assuming that would be possible?
I suggest you add a public method like SetYourDropdownValue(string val) to your master page.
In the load-eventhandler from the control page you hand over the selected value from the dropdown to your master page.
MyMainPage m = (MyMainPage)Master;
m.SetYourDropdownValue("your value");
There is an alternative way tho: Master Pages Reference.
You can set following reference tag in your control page markup:
<%# MasterType virtualPath="~/MasterPage.master"%>
Then it will be even easier:
Master.SetYourDropdownValue("your value");
In the SetYourDropdownValue-Method you save the value to a variable.
On the click eventhandler in your master page, you can then retreive the value from your variable.
Instead of passing a string you could also pass one or more controls, so you would just have to save the reference to it, instead of saving a value.
I have two types of pages .. the first is a display list and the second is a form to collect data.
I used a master page with two panels and each panel contains a ContentPlaceHolder .. the first contenet holder will show the input controls and the second one will show a unique message for every page after the user submit his data.
This is sort of a web moderator panel, where he'll add and display the items in the system to manage the website.
Now the problem is the second type of pages isn't related to the first type (Collecting data page) in the content area but it will share the same main menu and side menu!
so do I use two MasterPages and repeat the markup of the Main Menu and the Side Menu ? or can I use a base master page and the 2 master will inherit from it or what!!
I'm really confused on how to achieve this without breaking the good design concepts..
You can create a master page that has all the main layout information. Then have two sub master pages that inherit the main master page. These pages would just have minimal markup and inherit most of their layout / etc from the main master page
So I have my main page with buttons on top of it.
Below there's a MultiView (also tried with a Panel) and I want to display a different page (aspx) inside it when a user clicks the button on top of the page.
I've been trying to do this for 2 hours now and can't get this to work... No good info # Google.
Thanks in advance...
Try user controls instead of pages. I am not aware of any case where I ever needed this functionality.
Beside that, I'm rather sure that it is not supported to insert pages into other pages.
I'm looking for a way to access my page's controls.
I found this function that allows me to enter the ID of my control and the "root control"
and than it searches the children of the "root control" untill it finds my control id.
But the problem is that my control is nested in a table and the table is nested in a page in my master page.
whats the root control for the master page?
You can use the Master property of your content page to get the master page, then
FindControl to drill down till you get the control you are looking for (or you can use the function you already have).
See this howto on MSDN.
Try
(this.Page.MasterPage as MyMasterPage).SomeMasterPageMethodOrProperty
How can we use validation controls in a master page. The master page has some server controls and some html controls. Now if we place the validations controls on master page would it effect the child page as well. I read about validation controls and master pages from my own blog.
(Why do you want the validation in the master page?)
A better design choice is to put the validation controls together with the controls you want to validate.
If the controls are on the master page, then you can put validation controls in the master page. If they are on a page using the master page, put them there.
I suggest to make use of user controls. Group the actual control together with the validation control. This would give you much better control over your layout and validation. And as a bonus it's reusable.