I have a repeater, one columm of which contains a textbox on which is attached a JQuery datepicker along with an update button. So a user uses the datepicker to change the date, clicks update and it writes to the database.The original date and the
record id are stored in hidden fields.
protected void btnDateUpdate_Click(object sender, EventArgs e)
{
foreach (RepeaterItem item in Repeater1.Items)
{
HtmlInputText htmlDueDate = (HtmlInputText)item.FindControl("fccd");
HiddenField hidID = (HiddenField)item.FindControl("hidThisID");
HiddenField hidOldDate = (HiddenField)item.FindControl("hidPrevDueDate");
DateTime prevDueDate = Convert.ToDateTime(hidOldDate.Value.ToString());
DateTime newDueDate = Convert.ToDateTime(htmlDueDate.Value.ToString());
string ID = hidID.Value;
if (prevDueDate != newDueDate)
{
string query = "update [tblOrders] set Duebeforedate=CONVERT(datetime,'" + newDueDate.ToString() + "', 103) where [orderID] = '" + ID + "'";
//database stuff here
}
}
}
However, the newDueDate variable still holds the original due date. Consequently the old and new dates match and so the database doesn't get updated. How do I get it to store the new value?
Member
19 Points
102 Posts
Why is the change in an html input textbox not being detected in asp.net?
Mar 27, 2021 09:02 PM|bigyeti|LINK
I have a repeater, one columm of which contains a textbox on which is attached a JQuery datepicker along with an update button. So a user uses the datepicker to change the date, clicks update and it writes to the database.The original date and the record id are stored in hidden fields.
Which calls this function -
However, the newDueDate variable still holds the original due date. Consequently the old and new dates match and so the database doesn't get updated. How do I get it to store the new value?
Member
390 Points
280 Posts
Re: Why is the change in an html input textbox not being detected in asp.net?
Mar 27, 2021 10:52 PM|SurferOnWww|LINK
Please use Bind method instead of Eval method.
Member
19 Points
102 Posts
Re: Why is the change in an html input textbox not being detected in asp.net?
Mar 27, 2021 11:59 PM|bigyeti|LINK
I did change it to
But the same occurs, newDueDate holds the original value as in prevDueDate
Member
390 Points
280 Posts
Re: Why is the change in an html input textbox not being detected in asp.net?
Mar 28, 2021 01:02 AM|SurferOnWww|LINK
Remove readonly and try again.
Member
19 Points
102 Posts
Re: Why is the change in an html input textbox not being detected in asp.net?
Mar 28, 2021 01:14 AM|bigyeti|LINK
Makes no difference. Besides it needs to be readonly so they have to use the datepicker.
Member
390 Points
280 Posts
Re: Why is the change in an html input textbox not being detected in asp.net?
Mar 28, 2021 02:35 AM|SurferOnWww|LINK
I cannot reproduce your problem with the following sample similar to yours. I guess that something not shown in your code causes the issue.
.aspx.cs
.aspx
All-Star
52803 Points
15764 Posts
Re: Why is the change in an html input textbox not being detected in asp.net?
Mar 28, 2021 05:33 AM|oned_gk|LINK
Ensure, the repeater is not rebind every postback
Suwandi - Non Graduate Programmer
Member
19 Points
102 Posts
Re: Why is the change in an html input textbox not being detected in asp.net?
Mar 28, 2021 04:48 PM|bigyeti|LINK
Brilliant, that's fixed it.