Я пытаюсь сохранить данные методом на стороне клиента. Но когда я проверяю таблицу БД каждый раз, когда сохраняется дважды.
Я перепробовал все, но не могу решить проблему.
Клиентская сторона
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = strName;
cmd.Parameters.Add("@Country", SqlDbType.Int).Value = HotelCountry;
cmd.Parameters.Add("@City", SqlDbType.Int).Value = HotelCity;
cmd.Parameters.Add("@County", SqlDbType.Int).Value = HotelCounty;
cmd.Parameters.Add("@Town", SqlDbType.Int).Value = HotelTown;
cmd.Parameters.Add("@District", SqlDbType.Int).Value = HotelDistrict;
cmd.Parameters.Add("@Km", SqlDbType.Int).Value = HotelKm;
cmd.Parameters.Add("@Min", SqlDbType.Int).Value = HotelMin;
cmd.Parameters.Add("@Direction", SqlDbType.Int).Value = HotelDirection;
if (intId == 0)
{
cmd.CommandText = "INSERT INTO tabl_Hotels (fldName,fldCountry,fldCity,fldCounty,fldTown,fldDistrict,fldKm,fldMin,fldDirection) VALUES (@Name,@Country,@City,@County,@Town,@District,@Km,@Min,@Direction);";
try
{
cmd.ExecuteNonQuery();
Bootstrap.Success("Hotel saved successfully.");
}
catch (Exception ex) { Bootstrap.Danger(ex.Message); }
Response.End();
}
Кнопка HTML
<button type="button" id="btn-save" class="btn btn-primary" data-webmethod="hotels.aspx/save" >Save</button>
Java-скрипт
$(document).on('click', '#btn-save', function(e) {
var HotelName = document.getElementById('<%= HotelNameTextBox.ClientID %>').value,
HotelCountry= document.getElementById('<%= HotelCountryDropDownList.ClientID %>').value,
HotelCity=document.getElementById('<%= HotelCityDropDownList.ClientID %>').value,
HotelCounty=document.getElementById('<%= HotelCountyDropDownList.ClientID %>').value,
HotelTown=document.getElementById('<%= HotelTownDropDownList.ClientID %>').value,
HotelDistrict=document.getElementById('<%= HotelDistrictDropDownList.ClientID %>').value,
HotelDistancek=document.getElementById('<%= HotelDistancekTextBox.ClientID %>').value,
HotelDistancem=document.getElementById('<%= HotelDistancehTextBox.ClientID %>').value,
HotelDirection=document.getElementById('<%= HotelDirectionDropDownList.ClientID %>').value;
if(HotelDistancem=="" || HotelDistancek=="" || HotelName=="" || HotelCountry==0 || HotelCity==0 || HotelCounty==0 || HotelTown==0 || HotelDistrict==0 || HotelDirection==0){ bootbox.alert('Do not leave any blank.!');return false;}
alert('deneme');
});