master-pages

How to create a strongly typed master page using a base controller in ASP.NET MVC

ε祈祈猫儿з 提交于 2019-11-27 11:29:48
Following the NerdDinners example, I am interested in creating a strongly typed Master Page. In order to achieve this, I use a base controller which retrieves the data for the master page. All other controllers inherit this class. Similarly, I have ViewModels for the master page and any other views. The view ViewModel classes inherit from the master page's ViewModel . Question How should a child controller ensure that the master page's data is passed to the View without setting the properties of its ViewModel that pertain to the master page itself? My the master page will display a number of

active menu item - asp.net mvc3 master page

走远了吗. 提交于 2019-11-27 10:25:50
I've been scanning around trying to find an appropriate solution for assigning "active/current" class to menu items from the master page. The line is split down the middle with regards of whether to do this client vs server side. Truthfully I'm new to both JavaScript and MVC so i don't have an opinion. I would prefer to do this in the "cleanest" and most appropriate way. I have the following jQuery code to assign the "active" class to the <li> item...the only problem is the "index" or default view menu item will always be assigned the active class, because the URL is always a substring of the

Timer in UpdatePanel

浪尽此生 提交于 2019-11-27 09:32:22
I have an asp:UpdatePanel with an asp:Timer. These are in a Master/Content Page. The code is below: <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick"></asp:Timer> </ContentTemplate> </asp:UpdatePanel> But when the timer fires, I get the folowing error: Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response

Call Method in Master Page

匆匆过客 提交于 2019-11-27 09:25:18
I have a public method in my asp.net Master Page. Is it possible to call this from a content page and if so what are the steps/syntax? From within the Page you can cast the Master page to a specific type (the type of your own Master that exposes the desired functionality), using as to side step any exceptions on type mismatches: var master = Master as MyMasterPage; if (master != null) { master.Method(); } In the above code, if Master is not of type MyMasterPage then master will be null and no method call will be attempted; otherwise it will be called as expected. Uwe Keim Use the MasterType

jquery: find element whose id has a particular pattern

£可爱£侵袭症+ 提交于 2019-11-27 09:24:20
问题 I am trying to find a span element who has an id in a particular pattern. Its main use is to find certain elements rendered by an asp.net (aspx) page which is derived from a master page. 回答1: $('span').each(function(){ if( $(this).attr('id').match(/pattern/) ) { // your code goes here } }); problem solved. 回答2: Building on the accepted answer: It depends on what kind of pattern you're looking for. If your pattern is something like "MasterPageElement_CheckBox_4443", "MasterPageElement_CheckBox

how to set a default 'enter' on a certain button

一曲冷凌霜 提交于 2019-11-27 08:10:16
There is a textbox on a ContentPage. When the user presses Enter in that textbox I am trying to fire a 'Submit' button on this ContentPage. I'd like to fire off that particular button's event. Instead, there is a search textbox & button on the top of the page from a MasterPage, and this search button's event fires off. How do I control to fire off this ContentPage's submit button, instead of the MasterPage's search button? I am using Ektron CMS for my content management. The easiest way is to put the fields and button inside of a Panel and set the default button to the button you want to be

Are there nested master pages in ASP.NET MVC?

a 夏天 提交于 2019-11-27 07:53:23
I wanted to know if the MVC framework can leverage the Nested Master Page? If so does anyone have some info on how to achive this? Yep. I just saw a blog post about this at: http://jeffreypalermo.com/blog/asp-net-mvc-and-the-templated-partial-view-death-to-ascx/ Very cool stuff. Richard We use nested master pages frequently, in order to seperate layout from standard includes and site wide markup, like so: Site.Master: <%@ Master Language="C#" AutoEventWireup="true" Inherits="System.Web.Mvc.ViewMasterPage<PageViewModel>" %> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type"

Any way to prevent master pages from changing element IDs?

不打扰是莪最后的温柔 提交于 2019-11-27 06:56:12
问题 I'm looking at adding master pages to an existing site but have found that once I do, the elements' IDs get prepended with a code (e.g. ctl00_MainPageContent_ ). Unforunately, this breaks existing scripts on the page that use the original, unmodified element ID. I realize that I can replace it with <%= Element.ClientID %> but it'd be awesome if I could disable this behavior altogether. So, can I keep the original IDs? 回答1: The question was already answered in the previous post: Remove

find control in page

我只是一个虾纸丫 提交于 2019-11-27 06:46:13
问题 HTML <body> <form id="form1" runat="server"> <asp:Button runat="server" ID="a" OnClick="a_Click" Text="apd"/> </form> </body> Code protected void a_Click(object sender,EventArgs e) { Response.Write(((Button)FindControl("a")).Text); } This code works fine. However, this code: HTML <%@ Page Title="" Language="C#" MasterPageFile="~/Student/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Student_Default" %> <asp:Content ID="Content1" ContentPlaceHolderID="head"

ASP.NET Custom 404 Returning 200 OK Instead of 404 Not Found

一世执手 提交于 2019-11-27 06:35:19
After trying to setup my site for Google Webmaster Tools I found that my Custom ASP.NET 404 page was not returning the 404 status code. It displayed the correct custom page and told the browser that everything is OK. This is consider a soft 404 or false 404. Google doesn't like this. So I found many articles on the issue but the solution I want didn't seem to work. The solution I want to work is adding the following two lines to the code behind Page_Load method of the custom 404 page. Response.Status = "404 Not Found"; Response.StatusCode = 404; This doesn't work. The page still returns 200 OK