How can I two-way bind a TextBox to a code-behind property in ASP.NET?
问题 I cannot get any new entries in the textbox:txtMyString to set to the property MyString. What am I missing here? <asp:TextBox ID="txtMyString" Text='<%# MyString %>' runat="server" /> private string myString; protected string MyString { get { return myString; } set { myString = value; } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) myString = "1 way test works"; DataBind(); } 回答1: If you're doing two-way databinding, you need to use the Bind() method of the