[英]How to make Master Page to display a value on its label on each page
I am designing a Change Request(CR) module for our website, which allows users to raise a CR and submit it for review. 我正在为我们的网站设计一个更改请求(CR)模块,该模块允许用户提出CR并将其提交以供审核。 A workflow gets generated immediately after raising CR, so, user have to submit it by voting to his activity(Say activity as 'Submit to CCB').
提高CR后会立即生成工作流程,因此用户必须通过对其活动进行投票来提交它(说活动为“ Submit to CCB”)。 Then I am setting a label's value which is added to master page as 'In Review' I can see label value now, and immediately navigating to next activity(next page).
然后,我设置标签的值,该标签的值作为“正在审阅”添加到母版页中,现在我可以看到标签值,并立即导航到下一个活动(下一页)。 But I could not see the label's value there in next page.
但是我在下一页看不到标签的值。 As I am new to implementing master page concept, unable to find out the reason.
由于我刚开始实施母版页概念,因此无法找出原因。
WFLCRMaster.master WFLCRMaster.master
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="WFLCR.master.cs" Inherits="MasterPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="masterFormMIF" runat="server">
<div id="WorkflowStatus">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UserUpdatePanel" runat="server">
<ContentTemplate>
<asp:Label ID="WorkflowSignoffStatus" runat ="server"> </asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolderMIF" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
And I created a property in WFLCR.master.cs, And added <%@ MasterType VirtualPath="~/WFLCR.master" %>
to all pages. 我在WFLCR.master.cs中创建了一个属性,并将
<%@ MasterType VirtualPath="~/WFLCR.master" %>
到所有页面。
public string CRStatus
{
set { WorkflowSignoffStatus.Text = value; }
get { return WorkflowSignoffStatus.Text; }
}
Here is my Preliminary.aspx.cs 这是我的Preliminary.aspx.cs
public partial class Preliminary : System.Web.UI.Page
public string WFLCRStatus
{
get
{ object value = HttpContext.Current.Session["CRStatus"];
return value == null ? "" : (string)value;
}
set
{ HttpContext.Current.Session["CRStatus"] = value;
}
}
protected void BtnToCCB_Click(object sender, EventArgs e)
{
WFLCRStatus = "In Review";
Master.CRStatus = "In Review";
Response.Redirect("CCB.aspx");
}
}
Sets value to the label but on navigating to next page the label is empty. 将值设置为标签,但是在导航到下一页时,标签为空。
I created a property here in the plan of using it in master.cs's Form_Load
event to display the status. 我计划在master.cs的
Form_Load
事件中使用它来显示状态的计划中在此处创建了一个属性。 But I don't know how to use it there. 但是我不知道该怎么用。 Unable to create an instance there to access this property.
无法在此处创建实例以访问此属性。
Calling redirect after setting a label's value makes no sense. 设置标签值后调用重定向是没有意义的。
Master.CRStatus = "In Review";
Response.Redirect("CCB.aspx");
When you redirect, the framework sends an HTTP Redirect to the client browser, and the current request/response cycle ends and a completely new one begins. 重定向时,框架将HTTP重定向发送到客户端浏览器,并且当前的请求/响应周期结束,并且一个全新的请求/响应周期开始。 Meaning the entire page lifecycle is loaded again, including the master page.
这意味着将重新加载整个页面生命周期,包括母版页面。
To make this work, update your Session, perform the redirect, then in the Page_Load
of the next page check the Session to see if that value is there, and update the label accordingly. 为此,请更新您的Session,执行重定向,然后在下一页的
Page_Load
中检查Session以查看该值是否存在,并相应地更新标签。
WFLCRStatus.Status = "In Review"
Response.Redirect("CCB.aspx");
next page 下一页
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
if(!String.IsNullOrEmpty(Session["CRStatus"]))
{
Master.CRStatus = Session["CRStatus"].ToString();
}
}
}
尝试将默认值设置为WorkflowSignoffStatus
然后检查控件是否在BtnToCCB_Click
上返回正确的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.