master-pages

passing viewdata to asp.net mvc masterpages

一个人想着一个人 提交于 2019-12-04 07:21:28
I'm trying to pass ViewData to my asp.net mvc masterpage for an mvc usercontrol that I keep on a masterpage. For example, I created a dropdownlist of names as an mvc usercontrol and I put that in my masterpage. The problem I am running into is passing the ViewData to the masterpage. I found this article from Microsoft which has a decent solution but I was wondering if there are other "better" solutions out there. The thing I don't like about the solution in the link is that I have to change every controller to inherit from a new controller class. http://www.asp.net/learn/MVC/tutorial-13-cs

How to access controls inside a nested master page? why does it behave differently from content pages?

♀尐吖头ヾ 提交于 2019-12-04 05:27:58
Is there a difference between these two scenarios: (1) Accessing a property on a master page from a regular child (2) Accessing a property on a master page from a nested master page I tried to access a textbox in the master page from a content page like this: TextBox a; a = (TextBox)Master.FindControl("ayyash"); // Master is declared in MasterType directive defaultTextbox.Text = a.Text; // defaultTextBox is a textbox control inside default.aspx it works, but then when I applied the same method on a nested master page: TextBox a; a = (TextBox)Master.FindControl("ayyash"); // Master is declared

How to programmatically add stuff to contentPlaceHolder?

大城市里の小女人 提交于 2019-12-04 05:27:07
I have a master page and all of my pages are inheriting it. For formatting, I thought to place the content that differs from one page to another in a ContentPlaceHolder. Now, how can I insert everything into that? Since I am planning to populate the ContentPlaceHolder with stuff from a database I suppose I will have to do it programmatically. How can I add controls to ContentPlace Holder? I checked other answers , but I cannot access it by its ID. Should I use multiple ContentPlaceHolders from the beginning? Let's say I want to put movies. Should there be only one with all the images and

Does a MasterPage know what page is being displayed?

大憨熊 提交于 2019-12-04 03:32:14
When I navigate on a website utilizing MasterPages, does the application know what page I am on? If so, does it store it in an object I can access? The reason I am asking is so I can replace this: //masterpage <div id="nav_main"> <ul><asp:ContentPlaceHolder ID="navigation" runat="server"> </asp:ContentPlaceHolder></ul> </div> //content page(s) <asp:Content ContentPlaceHolderID="navigation" ID="theNav" runat="server"> <li><a href="default.aspx">Home</a></li> <li id="current"><a href="faq.aspx">FAQ</a></li> <li><a href="videos.aspx">Videos</a></li> <li><a href="#">Button 4</a></li> <li><a href="

Html.RenderPartial call from masterpage

徘徊边缘 提交于 2019-12-04 03:28:10
Here is a scenario: Let's say I have site with two controllers responsible for displaying different type of content - Pages and Articles. I need to embed Partial View into my masterpage that will list pages and articles filtered with some criteria, and be displayed on each page. I cannot set Model on my masterpage (am I right?). How do I solve this task using Html.RenderPartial? [EDIT] Yes, I'd probably create separate partial views for listing articles and pages, but still, there is a barrier that I cannot and shouldn't set model on masterpage. I need somehow to say "here are the pages" as an

how to change title of aspx page dynamically on page load

点点圈 提交于 2019-12-04 02:43:08
I had set of ASPX pages in which each page had different titles, but I want to put default title for pages which don't have a title. The default title must be configurable. If this is classic ASP.NET (not MVC) and you are using MasterPage then you can set default title in Page_Load event in MasterPage : protected void Page_Load(object sender, EventArgs e) { if (string.IsNullOrEmpty(Page.Title)) { Page.Title = ConfigurationManager.AppSettings["DefaultTitle"]; //title saved in web.config } } You can do this: Set the aspx header something like this <HEAD> <TITLE ID=CaptionHere RUNAT="server"><

Force browser to use new CSS

无人久伴 提交于 2019-12-04 01:11:34
问题 Is there a way to check if the user has a different version of the CSS cached by their browser and if so force their browser to pull the new version? 回答1: I don´t know if it is correct usage, but I think you can force a reload of the css file using a query string: <link href="mystyle.css?SOME_UNIQUE_TEXT" type="text/css" rel="stylesheet" /> I remember I used this method years ago to force a reload of a web-cam image, but time has probably moved on... 回答2: Without using js, you can just keep

I want a Master UserControl (a Master page, but for UserControls)

情到浓时终转凉″ 提交于 2019-12-03 16:44:04
ASP.NET master pages - essential things. However, I have a lot of very similar UserControls in my projects - it might be a standard layout for an AJAX ModalPopup, or something more involved. I wish I could get rid of some of my duplicated code (both in ascx files and code-behind) with some Master UserControls. Does anyone have any suggestions of a way to achieve this? The closest thing I can suggest for what you are looking for is a templated custom control . Unfortunately, sharing controls across projects is a lot easier if those things are custom controls, without an ascx file. this is an

ASP.NET Controller Base Class User.Identity.Name

╄→尐↘猪︶ㄣ 提交于 2019-12-03 16:23:04
As described in this post , I created an abstract base controller class in order to be able to pass data from a controller to master.page. In this case, I want to lookup a user in my db, querying for User.Identity.Name (only if he is logged in). However, I noticed that in this abstract base class the User property is always null . What do I have to do to get this working? Thanks a lot As Paco suggested, the viewdata isn't initialized till after you are trying to use it. Try overriding Controller.Initialize() instead: public abstract class ApplicationController : Controller { private

Error: “The file '/MasterPages/MainMaster.master' does not exist.” (Yes, this file does exist!)

倖福魔咒の 提交于 2019-12-03 16:12:04
I just got a new desktop computer with Windows 7 Pro as the operating system. I installed Visual Studio 2008 on to this new computer and tried to open a previously existing ASP.NET 3.5 solution that displayed perfectly fine on my previous computer (this previous computer used the Windows XP operating system, IIS6, and IE7 browser). However, in Windows7/IE8, I’m receiving the following error: Server Error in '/' Application. Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and