4

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 Answer 1

4

If you're doing two-way databinding, you need to use the Bind() method of the databinder.

<asp:TextBox ID="txtMyString" Text='<%# Bind("MyString") %>' runat="server" />

However, last time I checked, this was only supported if the textbox was inside a templated control such as Gridview, FormView or DetailsView.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.