Started a new project and first created a MasterPage. Immediately I then created a ContentPage using MasterPage. I then realised I forgot to add ContentPlaceHolder controls in the MasterPage, so I added them. Rebuilding the project did not add these controls to the content page.
As it is a new project, I can easily delete the ContentPage and readd it, but for convenience in the future, especially for larger projects, is there any way to automate this process without having to recreate the ContentPage/manually type the ContentPlaceHolder controls within the ContentPages?
Thanks.
try this,
please have a look at below link.
1st Master Page is created and then it will be applied to aspx Page (ex: Default.aspx) once you applied the master page to aspx, what ever changes done to master page will reflect in the aspx page as well..
http://office.microsoft.com/en-us/sharepoint-designer-help/change-the-current-master-page-HA010167165.aspx
Related
I'm working on a .NET WebForm app which has a master page. The .NET can not recognize many elements in the aspx file. For example it say Label is not a valid asp element and then says most likely reason is a malformed web.config file.
I double check my web.config and all looks good. The other webpages do not have same issue. The interesting thing is I do not have this issue inside the MasterPage.
I also tried recreate the page from scratch but still having same issue.
I'm using VS2019. Framework 4.6
You have to provide some sample code and markup. Also, if you have a master page, then that is a huge deal also. As a general rule, asp.net controls you drop on the page are able to be used from code behind. However, the code for the standard page(s) that we use as a "child" of a master pages means that code behind for the master page can easy use controls in master page. And code behind for the page being displayed in that master page ALSO can freely use its own controls. But controls between the master page and the working child page is VERY different matter.
And of course controls dropped into a repeater, or say listview (or even gridview) means that the one label or text box control is automatic repeated over and over. As such, you have to pull/get/use the one row out of that data bound repeating control, and then from that one repeating row grab the control in question.
So, saying I can't start my car, or I can't use or get a control?
We need more information as to the context of what control, where it is (in the master or child), and is the control perhaps nested inside of a data bound repeater, listview, gridview etc.
so, edit your question - add some details as to the markup, where it is (master or the child page), and we can help.
So, as a general rule, code behind in master page is free to use controls in the master page.
And in the web page you created, once again code behind is free to use controls in that page.
It can be more difficult to say have code in master page, and have it reference controls in the child page that is being displayed. But, then again, it is VERY rare that code in master page would need to reference or play with controls in the child page, since a master page will (usually) just be your main navigation bar - and it will be the same for many if not all pages you display - hence you master page really can't know what controls will exist in the current child page being displayed.
I have one problem. I want to setup master pages in my application. As I have too many aspx pages, I don't want to go to everypage and add asp:content tag in it. I want some dynamic way in which I can look into my page, copying it's html/other asp controls and adding it to dynamically created content template.
I know how to dynamically create content templates. But don't know whether it is possible copying aspx page's html and adding it to content template.
Let's say, In my aspx page's codebehind, on page_PreInit, I am adding following code.
base.AddContentTemplate("WebHeaderPH", new CompiledTemplateBuilder(new BuildTemplateMethod(this.getControl)));
getControl is a method which contain anything (html, text or may load a user control.)
This way, I am adding a content template dynamically.
Now my aspx page contents following code.
<span id="someid" runat="server">blah blah...</span>
Now what I want is, to get this span tag by it's id, and wrap it under asp:content. or may be in the above getControl method.
but putting this span on page, throw following error,
Content controls have to be top-level controls in a content page or a nested master page that references a master page.
Either I have to put, asp:content template on the page. but If I do this, then I don't need to create contentTemplate dynamically or keep whole page blank as I am creating contentTemplate dynamically. In both cases, I have to edit all my aspx pages.
Is there a way to get page's html and add it into contentTemplate without any need to edit aspx page?
I'm afraid you have to go step by step manually. It is indeed a design mistake, but it won't take you THAT long to change them all.
I've unfortunately made the same mistake as well and I fixed it by manually editing my pages.
I have two web-form pages in ASP, one for viewing a record and and another for editing it. I would like to have a link on each which popups a box to allow editing a certain property on the record. If I only placed it on the Edit page, I would use an UpdatePanel but I would have to copy and paste code if I wanted it on the View page as well. Is there a way to have the code in one area which be can be referenced and used from both pages?
Edit: I know I could make a custom control to handle it although it would include all its HTML on the page when the page first loads, not when the link is clicked.
Edit2: I wanted to avoid having the contents of the popup rendered when the page first loads but now I realize it's just a matter of not binding any data in it until the Postback occurs.
You can use a MasterPage for both the pages, and put the popup with UpdatePanel on the master page, so you can access it from both the pages.
Hope it helps.
Don't forget to upvote it if it solves you problem.
Thanks.. :)
Make the bulk of the panel a user control (ascx). Then just put a thin wrapper around it on both the pages where you need it. The bulk of the code is then in the ascx and ascx.vb and does not need to be written twice.
is it right to put script manager in master page ?
It isn't wrong, as such.
Really depends on your requirements.
If you need to use scripts in several pages that use the same master page, use ScriptManager in the master page.
Just keep in mind that you can only have one ScriptManager in the whole loaded page, so you can't add one in content pages as well.
See this article on MSDN for an example (Using the ASP.NET UpdatePanel Control with Master Pages).
I have a problem with my master pages. They have such inheritance order:
MainMaster1.Master can be nested by Nested1.Master, Nested2.Master, etc.
At the same time MainMaster can be duplicated and have working copies like MainMaster2, MainMaster3, etc.
Advise please how can I dynamically change the MasterPageFile of my Nested1, Nested2, etc. pages so that they can easily switch between MainMasters if needed?
I tried to treat the problem in Page_PreInit of the nested masters but couldn't get it entering this event handler. I also tried to change the masters in "protected void OnPreInit" of nested ones but result was the same.
Thanks,
Roman.
See the following article for several possible techniques you can use:
Dynamically Switching between Master Pages in ASP.NET MVC http://www.codeofrob.com/archive/2009/11/01/dynamically-switching-between-master-pages-in-asp.net-mvc.aspx
I think that's still what he meant, although it doesn't directly answer the question.
Page has a property called MasterPageFile which is used in the above article
Page also has a property called MasterPage
On MasterPage, there is a property called MasterPageFile (As in the above article)
MasterPage also has a property called MasterPage
While the example on that page covers with changing the master page on the page directly, you can do very much similar to the master page itself by recursing up through the master pages to find and change the one you want.
I hope that helps.