Bootstrap Modal popup not showing up first time - c#

While I first click this #btnRequestedProviderSelect button, bootstrap modal is not showing popup. But I second click it will come why?
$("#btnRequestedProviderSelect").click(function () {
$("#hdnORProvider").val('Requested');
$.ajax({
type: "Get",
async: false,
url: settings.ProviderSearchPopupURL,
data: {
coverageID: 0,
fromPage: settings.Frompage, HPID: $('#MemberHealthPlanID').val(),
LOBID: $("#MemberLOBID").val(), IPAID: $("#MemberIPAID").val()
},
success: function (data) {
$("#divProviderSearch").html(data);
$("#divProviderSearchPopup").modal();
$('#divProviderSearchPopup').modal({
keyboard: false
});
$('#divProviderSearchPopup').modal('show');
}
});
});
<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>

Related

from contact form to sendemail MVC5

Im having some contact form and I have in a HomeController method SendMessage, also in my form I have hidden success and error div.
How to call sendmessage, but to stay on the same page?
As commented by Igor, use an ajax call to hit your controller/method.
Here is an example -
<script>
$(function () {
$('#sendMail').click(function () {
$("#sendMail").empty();
$("#sendMail").attr("disabled", true);
$("#sendMail").append('<i class="fa fa-spinner fa-spin"></i>Please wait...');
$.ajax
({
url: '#Url.Action("SendMail", "ControllerName")',
type: 'POST',
datatype: 'application/json',
contentType: 'application/json',
data: JSON.stringify({ 'name': $('#txtName').val(), 'email': $('#txtEmail').val(), 'message': $('#txtMessage').val() }),
success: function (result) {
$("#sendMail").empty();
$("#sendMail").append('Send Message');
$("#sendMail").attr("disabled", false);
},
error: function (result) {
$("#sendMail").empty();
$("#sendMail").append('Send Message');
$("#sendMail").attr("disabled", false);
}
});
})
})
</script>
In above javascript function -
When user clicks on button with text 'Send Mail' and id = sendMail, I disabled the button so the user won't click it multiple times and change the text of button to 'Please wait' and add a spinner for dramatic effect. I also send email of the user and name and message with the ajax call. On ajax success, I show a toaster with success message and remove the spinner and please wait text from the button and set 'Send Mail' text again.
I removed toaster javascript part in case you want to use other notification method. Good luck.

asp.net mvc why ajax response after refreshing the page

this method I'm writing database and folder operations. no problem at all
the response is coming but the page refreshes. The problem disappears when I cancel folder operations.I don't want the page refreshed
$(".btnSave").on("click", function (e) {
var model = {
"ProductName": productName, "BrandCategoryId": BrandCategoryId, "TaxRate": taxRate, "WareHouseId": WareHouseId, "ProductId": ProductId, "PurchasePrice": purchasePrice, "Count": count, "Discount": discount
};
e.preventDefault();
e.stopPropagation();
swal({
title: "Lütfen Bekleyin", text: "Stok kayıt yapılıyor..", showConfirmButton: false, allowOutsideClick: false
});
$.ajax({
method: "POST",
url: "/Warehouseworker/JavaScript/NewStock",
data: model,
dataType: "json",
success: function (response) {
if (response.ModelErrors) {
var errors = response.ModelErrors;
swal.close();
showErrors(errors);
}
if (response.errorMsg) {
swal({ title: "Uyarı", text: "hata var", type: "warning" });
}
if (response.success) {
swal({ title: "Stok kaydı gerçekleştirilmiştir", text: "", type: "success" });
}
}
});
});
Are you using a button and it is in a form?
If so, make the button type="button" and it won't refresh the page. The default behavior is to post the form that it is in.
It it's a link then add the href=javascript:;.

Disable ASP:dropdownlist based on the selection of another ASP:Dropdownlist.value

I have two asp.net dropdownlists that I want to manipulate clientside with Javascript.
These two dropdowns are inside a modal open: function()
When dropdown1.value == "me"
I want dropdown2.value to be disabled
How can I accomplish this?
$(document).ready(function () {
if (document.getElementById('<%=dropdown1.ClientID%>').value == 'Me')
document.getElementById('<%=dropdown2.ClientID%>').disabled = true;
});
(optional) Part 2 I need to set an entity framework value to null after dropdown2 has been disabled how could I accomplish this without a postback?
Part 1:
$(document).ready(function ()
{
if($("#<%=dropdown1.ClientID%>").val() == "Me")
$("#<%=dropdown2.ClientID%>").prop("disabled",true);
});
Part 2 :
You would need to make an ajax call to a code behind or webservice to do that.
.ASPX
$.ajax({
type: "POST",
url: "PageName.aspx/CodeBehindMethodName",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
},
error: function (error) {
}
});
.ASPX.CS
[WebMethod]
public static void Test()
{
// Call EF code
}

Custom button from jquery dialog not calling controller action

I have main view and open a dialog by using the jquery dialog like below.
function ShowDialog() {
dialog = $('#reassign').dialog({
autoOpen: false,
height: 500,
width: 700,
modal: true,
open: function () {
$('#reassign').load('/ItemsList/Reassign');
}
});
dialog.dialog("open");
}
The content of the dialog is in a PartialView. I have a button on that dialog and I want to call another action to load a list of users. This how I call the action method. But its not getting fired.
$('#searchUser').click(function () {
var search = $('#search').val();
alert(search);
$.ajax({
ur1: '#(Url.Action("Users", "WorkItemsList"))',
type: 'POST',
success: function(result) {
alert(result);
}
});
});
Am I missing something?

Bootstrap Css class in dynamic button on Ajax Call

I wanted to apply bootstrap button to dynamically create buttons via Ajax Call.In my code without bootstrap css class it's working on just default buttons But i want to apply bootstrap button When i use bootstrap css class --> class=btn btn-large btn-primary,Then it's not working
My Code
function LoadSpecialFilesToUser() {
debugger;
var newurls = '<%= ResolveUrl("/WebMethods.aspx/GetSpecialFilesToUsers") %>';
$.ajax({
url: newurls,
type: "POST",
data: JSON.stringify({ Id: "<%=GetUserID()%>" }),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (Result) {
$.each(Result.d, function (key, value) {
$("#SpecialFiles").append("<button class=btn btn-large btn-primary><a href=" + value.FilePath + "/>" + value.Caption + "</button>");//<-- In here without class=btn btn-large btn-primary.It's working
});
},
error: function (e, x) {
alert(x.ResponseText);
}
});
}

Categories