简体   繁体   English

如何在 ASP.NET 中动态设置段落文本?

[英]How to set a paragraph text dynamically in ASP.NET?

I am creating a website in asp.net.我正在 asp.net 中创建一个网站。 My website has an admin page.我的网站有一个管理页面。 The admin will use this page to daily update website's content.管理员将使用此页面每天更新网站的内容。 This content will get reflected to the main website.此内容将反映到主网站。 I have learned from the following link that how we can pass values from one page to another- How to pass values across the pages in ASP.net without using Session我从以下链接中了解到我们如何将值从一个页面传递到另一个页面 - 如何在 ASP.net 中的页面之间传递值而不使用 Session

I am using Application variable.我正在使用应用程序变量。

Admin.aspx管理员.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管理.aspx.cs

protected void b1_Click(object sender, EventArgs e)
        {
            Label_DailyMsgId.Text = DailyMsgID.Text;
            Application["DailyMessage"] = Label_DailyMsgId.Text;
                
        }

Home.aspx主页.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>

To set the paragraph, I want to do something like below.要设置段落,我想做如下的事情。 But it is not recognising the paragraph Id.但它不识别段落 ID。

Home.aspx.cs主页.aspx.cs

  protected void Page_Load(object sender, EventArgs e)
        {
            DailyMessage.Text = Application["DailyMessage"].ToString();
        }

How do I set the paragraph?如何设置段落?

Both Admin and Home page are under the same solution. Admin 和 Home 页面都在同一个解决方案下。

This issue got resolved.这个问题得到了解决。 I was missing我失踪了

runat="server"

Here is the updated code -这是更新的代码 -

Home.aspx主页.aspx

                    <p id="DailyMessage" runat="server"></p>
                   

Home.aspx.cs主页.aspx.cs

 protected void Page_Load(object sender, EventArgs e)
        {
            DailyMessage.InnerText = Application["DailyMessage"].ToString();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM