【发布时间】:2022-01-02 12:06:52
【问题描述】:
我正在 asp.net 中创建一个网站。我的网站有一个管理页面。管理员将使用此页面每天更新网站的内容。此内容将反映到主网站。我从以下链接中了解到我们如何将值从一页传递到另一页- How to pass values across the pages in ASP.net without using Session
我正在使用应用程序变量。
Admin.aspx
<form runat="server">
<div>
<asp:TextBox id="DailyMsgID" name = "DailyMsgName" runat="server"></asp:TextBox>
<asp:Button id="b1" Text="Submit" runat="server" OnClick="b1_Click" />
<asp:Label ID="Label_DailyMsgId" name="Label_DailyMsgName" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
Admin.aspx.cs
protected void b1_Click(object sender, EventArgs e)
{
Label_DailyMsgId.Text = DailyMsgID.Text;
Application["DailyMessage"] = Label_DailyMsgId.Text;
}
主页.aspx
<!-- Page content-->
<div id="div1" class="container-fluid">
<h1 id="myhead" class="mt-4">Welcome to the Official Website of ABC</h1>
<p id="DailyMessage"></p>
</div>
要设置段落,我想做如下的事情。但它无法识别段落 ID。
Home.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
DailyMessage.Text = Application["DailyMessage"].ToString();
}
如何设置段落?
Admin 和 Home 页面在同一个解决方案下。
【问题讨论】: