Resolved How to set a paragraph text dynamically in ASP.NET?

Anonymous

Well-known member
Joined
Sep 29, 2020
Messages
70
Programming Experience
Beginner
I am creating a website in 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 am using Application variable to pass values from one page to another.

Admin.aspx


C#:
  <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


C#:
protected void b1_Click(object sender, EventArgs e)

        {

            Label_DailyMsgId.Text = DailyMsgID.Text;

            Application["DailyMessage"] = Label_DailyMsgId.Text;

                

        }

Home.aspx

C#:
<!-- 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.

Home.aspx.cs


C#:
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.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
5,712
Location
Chesapeake, VA
Programming Experience
10+
It does not recognize it in the code behind because you are missing the runat="server".
 
Top Bottom