刷新母版页 [英] Refresh of a Master Page

查看:110
本文介绍了刷新母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个母版页,其中包含用于显示消息的标准代码,因此:

I have a master page which has standard code in it to display messages, thus:

<% if (TempData["message"] != null) { %>
        <div class="statusMessage"><%= TempData["message"] %></div>
<% } %>


但是,当我在页面提交后设置TempData时,回发后重新显示页面视图时,似乎不会刷新母版页.因此,不会显示回发中设置的任何消息.

这同样适用于在主页中创建的菜单栏.仅当用户通过身份验证并且在Roles ="Admin"中时,才会显示最后一个条目Administration.如果管理员用户登录,则母版页不会再次刷新以显示额外的菜单项.

如何刷新母版页?

Roger H


However, when I set TempData after a page submit, the master page does not seem to be refreshed when the page view is redisplayed after the postback. Therefore, any message that was set in the postback is not being displayed.

The same applies to a menu bar which is created in the master page. The last entry, Administration, is only displayed if the user is Authenticated and in Roles = "Admin". If an Admin User logs in, the master page is again not being refreshed to show the extra menu item.

How can the master page be refreshed?

Roger H

推荐答案

尝试一下:

母版页代码背后:

Try this:

Master Page code behind:

public partial class Site1 : System.Web.UI.MasterPage
{
    public Dictionary<string, string> TempData;
}



母版页:



Master Page:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <% if (null != TempData && !string.IsNullOrEmpty(TempData["message"]))
           { %>
        <div class="statusMessage">
            <%= TempData["message"] %></div>
        <% } %>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>



页面:



Page:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2"

    MasterPageFile="~/Site1.Master" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:Button ID="btnsubmint" runat="server" Text="submit"

    onclick="btnsubmint_Click" />
</asp:Content>



后面的页面代码:



Page code behind:

public partial class WebForm2 : System.Web.UI.Page
{
    protected void btnsubmint_Click(object sender, EventArgs e)
    {
        Site1 master = (Site1)(this.Master);
        if (null == master.TempData) master.TempData = new Dictionary<string, string>();
        master.TempData.Add("message", "Hello");
    }
 }



祝你好运



Good luck


Ed
关于ASP.NET MVC的全部要点是,提交"按钮不会生成按钮单击事件,并且没有CodeBehind模块来捕获它.表单标签上都没有runat="Server".内容页面本质上仅包含要显示的HTML,该HTML由Controller打开,该HTML可能会或可能不会传递一些数据. Controller还处理回发,然后重新显示页面并刷新数据.

在此范例中,我看不到有任何影响重新显示母版页的方法.

罗杰·H
Ed
The whole point about ASP.NET MVC is that Submit buttons do not generate a button click event and there is no CodeBehind module to trap it. Neither is there a runat="Server" on the form tag. The content page essentially contains only the Html to be displayed which is opened by the Controller, which may or may not pass some data over. The Controller also handles the postback and then causes the page to be re-displayed with a data refresh.

I do not see any way within this paradigm to affect a redisplay of the master page.

Roger H


这篇关于刷新母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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