如果我在 ASP.NET 页面上有 10 个标签,有没有一种方法可以通过编程方式根据值选择要设置的标签之一?
IE
<asp:Label runat="server" ID="errormsgLbl1" CssClass="errorMessage"/>
<asp:Label runat="server" ID="errormsgLbl2" CssClass="errorMessage"/>
<asp:Label runat="server" ID="errormsgLbl3" CssClass="errorMessage"/>
<asp:Label runat="server" ID="errormsgLbl4" CssClass="errorMessage"/>
<asp:Label runat="server" ID="errormsgLbl5" CssClass="errorMessage"/>
<asp:Label runat="server" ID="errormsgLbl6" CssClass="errorMessage"/>
<asp:Label runat="server" ID="errormsgLbl7" CssClass="errorMessage"/>
<asp:Label runat="server" ID="errormsgLbl8" CssClass="errorMessage"/>
<asp:Label runat="server" ID="errormsgLbl9" CssClass="errorMessage"/>
<asp:Label runat="server" ID="errormsgLbl10" CssClass="errorMessage"/>
然后在我的代码隐藏中
var labeltochange = "errormsgLbl1";
.
. Magic here
.
labeltochange.text = "message";