I use masterpage in asp.net web form, I use span to display message to users
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<div class="col-md-10 col-sm-10">
<span id="spnMessage" class="btnText" runat="server"></span>
</div>
</asp:Content>
and code is:
spnMessage.InnerText = "Add record successfully ";
but in runtime id of span change to "ContentPlaceHolder2_spnMessage" and my code does not work. What should I do?
Change the
span
into a Literal. Then there will be no more issues with ID conflicts.Then accessing the Literal from code behind will always work.
Or if you need to use the
<span>
element for CSS purposes, you can still wrap the Literal with it.You could also use a aspnet
Label
. A label will generate it's own<div>
tag in HTML.Will become