I am trying to do the following:
<asp:TextBox ID="txtName" runat="server" Text="<%= Name %>" />
When I execute my page it gets output as <%= Name %> instead of actually doing a response.write.
I tried modifying it to use the <% Response.Write(Name) %> instead but it did the same thing, putting the text there instead.
I can do this just fine:
<input type="text" value="<%= Name %>" />
That will actually work. Why doesn't this work when I use the TextBox control? Is there another way I'm supposed to do this?
Either use code behind:
txtName.Text = Name;
Or, add Page.DataBind()
in your code behind and change the syntax of your control to:
<asp:TextBox ID="txtName" runat="server" Text="<%# Name %>" />
Note the #
rather than the =
. #
represents a data-binding expression
Because the control is rendered differently than a literal. Use the codebehind to set the Text
property.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.