change element in another page asp.net - asp.net

I have a master page and I want to change his elements from different page.
Actually the goal is to create the site management page, it will be possible for example to change a master page menu.
Thanks.

Provide a public method in your MasterPage that changes it's content, for example:
public void changeMenuSource(object dataSource)
{
this.Menu.DataSource = dataSource;
this.Menu.DataBind();
}
Then you can call it from your ContentPages as well as from any UserControl inside of any ContentPage in the following way(YourMasterPage is the actual type of the MasterPage):
((YourMasterPage)this.Page.Master).changeMenuSource(newDataSource);

I assume your site management uses some kind of database? Store menu (menu nodes) in database (create tables or scheme of tables) and use that as your menu source. On site management page create commands for insert/update menu nodes for specific page, on your pages (or masterpage) create read commands for inserted/updated values and render your menu from source.
Here is example I used it before:
http://aspalliance.com/822_Building_a_Database_Driven_Hierarchical_Menu_using_ASPNET_20

Related

Web user control as masterpage with two child views

I'm building custom .NET web user control for Umbraco, which looks like single page, with a sidebar (which holds IDs of content items) on the left side of page, and two different content views(which have content by id displayed here) to the right of it.
The thing is, i don't know if this is possible to do something like masterpage/childs principle(in terms of this web user control), so i'll have something like "Master page" with this sidebar, and will render one of two child views to the right of it, depending on id selected from sidebar?
Or maybe there should be some workaround used here?
Will be much appreciated on any help here(like information about how that can be done, what information shall i seek for etc.), as i'm completely new in this kind of stuff.
From what I know, what you could possibly do is have your "master control" set up in your web user control, and then dynamically create one of two custom controls based on the values you choose from your master control. This is also known as a Master-Detail solution (provided a link).
Tutorial 10: Master/Detail Using a Selectable Master GridView with a Details DetailView
If each of these controls was a user control in itself nested inside another user control, you could for example have three web user controls: Master, Child1 and Child2.
Using code-behind, you could easily create dynamic controls based on those you select from your Master control using Events to the "container page". Using these events, you could dynamically create your user controls/pass them variables, and so on.
Here are some articles about events, if you are interested:
Events in User Controls
Events in ASP.NET Server Controls
If you didn't want to dynamically create your controls, it wouldn't be difficult to bind them on demand dependent on the variable from your Master control, and hide them if they are not being used/bound.
You could also use the public properties of a control you define yourself. So say you have your Child1 user control, you could define a public property in the code behind. You can access this in design-time as well.
public int SpecialID { get; set; }

how create shared web from in asp.net

I am working on asp.net application for reporting. I need to develop round about 50+ reports. On each report I need selection criteria that may contain start-date , end-date, name , company etc on almost every .aspx page. these controls can be of type like dropdown, textbox or calender etc .
Any idea to use one editable + shared (not 100% same) web form on every page.
Using ASP.NET custom controls will allow you to create a module that you can insert into all of your pages.
You can also check this out to get you started more quickly.
http://www.codeproject.com/Articles/1739/User-controls-in-ASP-NET
If you want to make it similar but not 100% same for all apps then just create public properties that you can use to adjust control properties on different pages. For example if some text box should be visible on some page and not visible on other just create a public property in your control named something like EnableTextBoxABC
You can create ASP.NET Custom Controls.

Can I use more than one master page on a sharepoint site?

I have been asked to modify a home page to a completely new design, all other pages will remain exactly the same.
I am a little green when it comes to sharepoint. I have created the masterpage, however when i choose set as default master page or set as customer masterpage it changes for the entire site. I would only like to change the home page.
The only option I have come across at this point would seem to be Detach from page layout which would not be ideal as the remainder of the site may be pushed into this new skin
Programmatically changing the masterpage for this particular page is the only option as nigel says.
You can create a custom page layout for the homepage and then set the masterpage on the pre-init as shown below:
public class MyPageLayout:PublishingLayoutPage
{
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
this.MasterPageFile = "~/_catalogs/masterpage/mynewmasterpage.master";
}
}
SharePoint Publishing pages inherit from the Microsoft.SharePoint.Publishing.PublishingLayoutPage class, which sets the master page programmatically to the site defined custom master page. There is no way to override this behaviour other than to do so through code yourself.
From your description, it sounds like you need a new page layout and not a master page.
Master page is typically used for navigation, footer, and similar outer layouts and affects all pages.
Page layout is used for specific designs and when you create a new page you can use it as template, starting point for a specific layout and typically displays your contents

How do I create a function common to all the pages in ASP.net?

I'm making a website that has a menu on all the pages that needs to be changed frequently. Right now I'm copying the code of the menu in all the pages, and so, if the menu needs to be changed, I have to open each page and change the menu there.
Is there any way by which I could define a function in a file somewhere that just writes the menu code using Response.Write() and then keep calling that function on all the pages that need the menu? That way whenever I'd need to make changes to the menu, I'll only make it in the function definition.
Have a look at a user control or master pages. Be more elaborate, so we can help you better.
It sounds like you should consider using a user control for the menu.
Master page is the perfect candidate.
Add the menu in master page.
You can also create a user control for this.
But if you want a function for doing a common task through out the site then create a class
and add the function is that class. Create an object of that class and call the function
anywhere in the site.
If you define a Menu in your Master Page it should refelect in all child pages.
All you need to do is create a Master Page and define your Menu in that.
After that you should create your child page using option >> WebForm using MasterPage
Apart from that for any other functions which are in Master page you can call them in your child page like this:
You can call method inside a MasterPage like this:
var master = Master as MyMasterPage;
if (master != null)
{
master.Method();
}

ASP.NET Nested masterpages, how to set content in the top page from the aspx file?

I have some content from a CMS that I need to move to raw asp.net pages. Since the templates are nested I guess I can use nested masterpages to acomplish it, but I'm finding that I can't set values on the top masterpage from the deep child page.
Here is a sample. I have several nested masterpages with contentplaceholders:
top master (with contentPlaceHolder1)
nested master, dependent on top master (with contentPlaceHolder2)
aspx page, dependent on nested master, defines content for contentPlaceHolder1 and 2
The problem is that asp.net doesn't allow me to have the value of contentPlaceHolder1 defined in the content page, it should be defined in the nested master. But the point is that the client page knows that value, not the template masters (for instance, the page knows about the graphic it has to display on the the top, but the placeholder for the graphic is the top master).
How can I set values in the aspx page to be rendered in the top master?
Normally you would have to do the following:
setup a public property on your master page
add the #MasterPage declaration to the top of any content page that you want to access the property in
access the property like Master.YourPageProperty = "value";
In the case of nested masterpages you must also setup pass-through public properties using the same method above but doing it in your nested master page (ie define the nested master pages master page and set up dummy public properties that just set the value passed in to the nested master to the top master).
Try looking at this article to reinforce the ideas I have touched upon:
http://msdn.microsoft.com/en-us/library/c8y19k6h.aspx
I normally make all of my .aspx pages inherit from a base page, and on this page I set up properties for any data that I want to share. Then, on your top master page you can cast the current page to type basepage and then have access to all the data.
I usually expose the base page as a property on my master page also, that way I can do a soft cast and do null checking if I have any case where a page that doesn't inherit from my base page is using the master page.

Resources