Reputation: 1007
Below is the content of my Default.aspx
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
WELCOME
</h2>
<p id="exampleId">
I want to edit here
</p>
</asp:Content>
I want to be able to find the control with ID "exampleID", and write something into it using c#.
Upvotes: 1
Views: 2754
Reputation: 2075
You have few options here:
Add asp.net server side control "literal" inside p
<p>
<asp:Literal ID="exampleId" runat="server" />
</p>
Don't use Label for that, as this will render with additional SPAN, which you don't want.
Hope it helps.
Upvotes: 1
Reputation: 10095
runat = "server" was missing in the tag to access it from code behind.
HTML
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
WELCOME
</h2>
<p id="exampleId" runat = "server">
I want to edit here
</p>
</asp:Content>
C# Code
exampleId.InnerText = "Your text";
Upvotes: 4