hello,
i have this code, its strange behave, when user select dates from textbox thru javascript button click even fires but its insert the data in table 3 times not sure why
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/css/bootstrap-datepicker3.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.7.1/js/bootstrap-datepicker.min.js"></script>
<script type="text/javascript">
$(function () {
var selectedDates = [];
datePicker = $('[id*=txtdate]').datepicker({
startDate: new Date(),
minDate: 0,
multidate: true,
format: "mm/dd/yyyy",
daysOfWeekHighlighted: "5,6",
language: 'en',
daysOfWeekDisabled: [0, 6]
});
datePicker.on('changeDate', function (e) {
if (e.dates.length <= 3) {
selectedDates = e.dates;
setTimeout(function () {
document.getElementById("<%=Button1.ClientID %>").click();
}, 3000);
} else {
datePicker.data('datepicker').setDates(selectedDates);
alert('You can only select 3 dates.');
}
});
});
</script>
<asp:TextBox ID="txtdate" runat="server" AutoCompleteType="Disabled" ></asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
string values = txtdate.Text;
foreach (string value in values.Split(','))
{
PetWalkDateTime df = new PetWalkDateTime();
Guid id = Guid.Parse("1382f89c-fb25-4924-998a-a4277f5457a1");
df.ServiceBookingGUIDID = id;
df.PetWalkdate = DateTime.Parse(value.ToString());
df.PetWalkTime = "0";
db.PetWalkDateTimes.Add(df);
db.SaveChanges();
//crud(id, DateTime.Parse(value.ToString()), "0");
//do something with individual value
Label1.Text += value;
}