I have the following TextChanged event –
protected void DataList1_SelectedTextChanged(object sender, EventArgs e)
{
TextBox chk = (TextBox)sender;
DataListItem item = (DataListItem)chk.NamingContainer;
TextBox txt = (TextBox)DataList1.Items[item.ItemIndex].FindControl("aTextBox");
string text = txt.Text;
WebService1 ws = new WebService1();
ws.updateA(text, newText)
}
where the ws.updateA web method needs text which is the original text in the textbox and newText which is the text after the changed event has been fired.
My problem being how can I distinguish between the original text and the newText to use in the web method as the method is updating the data table with the new text uses the original to update?
The SQL is –
UPDATE table SET term='" + newText + "' WHERE termText= '" + text + "'
You should really use a primary key to identify which row to update. Updating by a text string in the where clause isn’t a good practice.
By the time
SelectedTextChangedevent is fired, the old value of the control is long overwritten in the page life cycle.If it is critical to know the old value, you should persist in across PostBacks using the
ViewState.Refer: How to: Save Values in View State