如何在许多页面上显示常用文本。 [英] How to show common text on many pages.

查看:116
本文介绍了如何在许多页面上显示常用文本。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have 1000 of page in asp.net application with many master page. I want to show Happy new year on every page. So how it can be achieved without apply code on every page or master page?





我尝试了什么:



如果不在母版页上应用任何内容,我不知道如何实现它。



What I have tried:

I don't know how to achieve it without apply anything on master pages.

推荐答案

在生活中,当我遇到问题时,我的意图始终是保持简单。在这种情况下,你需要做一些工作,但这是值得的。我的建议是创建一个Web用户控件。



Web用户控件是一个Web窗体,但它可以放在多个Web窗体上,甚至可以放在母版页。如果是我,我会创建一个Web用户控件并将其放在每个母版页上。如果你有1000个Web表单的10个母版页,你仍然会节省很多时间,将来会更容易管理。



第一个释放你,你需要编译和发布。让我们说从现在开始一个月,如果您的文化中有一个特殊的假期并且您不想完整发布,那么您只能将文本更新为您的1个Web用户控件,它将通过走出网站。下面是母版页中使用的Web用户控件示例。



In life when I have a problem, my intentions are always to keep it simple. In this case, you'll need to do a little work, but it will be worth it. My recommendation is to create a Web User Control.

A Web User Control is a Web Form, but it can be placed on multiple Web Forms and can even be put on Master Pages. If it were me, I would create 1 Web User Control and put it on each Master Page. If you have 10 Master Pages for the 1000 Web Forms, you'll still be saving a lot of time and it will be easier managed in the future.

The first release you do, you would need to compile and publish. Let's say a month from now in the future, if there is a special holiday in your culture and you don't want to do a full release, then you can only update the text to your 1 Web User Control and it will be updated through out the site. Below is sample of a Web User Control used in a Master Page.

//Here is the Web User Control named Head.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Head.ascx.cs" Inherits="MyWebsite.UI.Web.WUC.Head" %>
<% @ OutputCache Duration="3600" VaryByParam="None" VaryByCustom="browser" %>
<!-- **** above I am setting the Web User Control to cache for 1 hour **** -->
	<div id="title">This is Text I want to display in EVERY PAGE!
	</div>





//Here is my Master Page named Main.Master
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Main.master.cs" Inherits="MyWebsite.UI.Web.Templates.Main" %>
<%@ Register Src="../WUC/Head.ascx" TagName="Header" TagPrefix="Head" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div id="struct">
<Head:Header ID="head2" runat="server" />
<!-- **** the tag above is the Web User Control being called in the Master Page **** -->
    <div id="content">
        <div id="main">
    <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        
    </asp:ContentPlaceHolder>
        </div>
    </div>
</div>
</form>
</body>
</html>


可以将常用页面片段包含在所有其他页面中以显示您的消息。
May be you can include common page fragment to all other pages to display your message.

所以你想在不更改任何代码的情况下在每个页面上显示内容?您的选择相当有限,您最好的选择可能是响应过滤器。这将允许您在.net呈现它之后但在将其发送到客户端之前将html注入页面。这篇文章向您展示了如何从html中删除空格,你需要在body标签之后注入一些html的东西



使用Response.Filter属性从ASP.NET输出中删除白色字符 [< a href =http://www.codeproject.com/Articles/9521/Removing-White-Chars-from-ASP-NET-Output-using-Restarget =_ blanktitle =New Window> ^ ]



如果你谷歌HttpResponse.Filter你可以找到更接近你想要做的例子。
So you want to show something on every page without changing any of the code? Your options are fairly limited then, your best bet is probably a response filter. That will let you inject html into the page after .net has rendered it but before it is sent to the client. This article shows you how you remove spaces from the html, you'd need something that injected some html after the body tag or something

Removing White Chars from ASP.NET Output using Response.Filter property[^]

If you google HttpResponse.Filter you can probably find examples closer to what you are looking to do.


这篇关于如何在许多页面上显示常用文本。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆