ASPX Page
<asp:Label ID="lbk" runat="server" Text='<%= _imgPath %>' />
Code behind
protected void Page_Load(object sender,开发者_StackOverflow EventArgs e)
{
_imgPath = "MyName";
}
My expectation was that it should render
<span id="lbk">MyName</span>
But it is rendering
<span id="lbk"><%= _imgPath %></span>
Is this correct behavior?
Try this:
<asp:Label ID="lbk" runat="server" Text='<%# _imgPath %>' />
protected void Page_Load(object sender, EventArgs e)
{
lbk.Text = "MyName";
}
you dont need _imgPath
.
For something simple like setting the text of a Label, use the Page_Load
event in the code-behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
lbk.Text = "MyName";
}
}
Of if you'd rather use a script on the page, you can do this:
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
lbk.Text = "MyName";
}
}
</script>
精彩评论