views:

46

answers:

2

I have a asp.net page with a datalist with a textbox and a button on it, on page load the textbox gets text in it, if I change the text and press the button the text doesn't get updated.

What am I doing wrong?

{
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DataTable table = CategoryAccess.GetProducts();

        ProductList.DataSource = table;
        ProductList.DataBind();
    }
}

protected void btn_Click(object sender, EventArgs e)
{
    string Name = textbox.Text;

    CategoryAccess.UpdateProducts(Name);
}
}
A: 

Try to add EnableViewState property in your textBox control and set the value to true.

e.g.

<asp:TextBox ID="textBox1"
             EnableViewState="true"
             MaxLength="25"
             runat="server"/>

or you can do it programatically:

protected void Page_Load(object sender, EventArgs e)
{
    textBox1.EnableViewState = true;
}
yonan2236
Dosent work, if I change: textbox.text = "hello"; string Name = textbox.Text; the value get updated to hello. It's like the textbox dosent notice that the text is changing.
Nicklas
A: 

You need to bing again the new data...

protected void btn_Click(object sender, EventArgs e)
{
    string Name = textbox.Text;

    // you update with the new parametre
    CategoryAccess.UpdateProducts(Name);

    // you get the new data
    DataTable table = CategoryAccess.GetProducts();

    // and show it
    ProductList.DataSource = table;
    ProductList.DataBind();
}
Aristos