Jquery
JQuery
Dropdowninhalt anhand anderem Dropdown auffüllen:
$(function () {
$("#ddlVerfuegbarePlaetze").change(function () {
var option = $(this).val();
$.ajax({
type: "POST",
url: "Reservierung.aspx/GetAnzahlFreiePlaetze",
contentType: "application/json; charset=utf-8",
data: "{'fuehrungId':'" + option + "'}",
success: function (msg) {
fillDropDown(msg.d);
},
error: function (res, status) {
if (status === "error") {
// errorMessage can be an object with 3 string properties: ExceptionType, Message and StackTrace
var errorMessage = $.parseJSON(res.responseText);
alert(errorMessage.Message);
}
}
});
});
});
function fillDropDown(freiePlatze) {
$("select#ddlAnzahlTeilnehmer").empty();
$("select#ddlAnzahlTeilnehmer").append(
$("<option>").val("").html("")
);
for (var i = 1; i < freiePlatze; i++) {
$("select#ddlAnzahlTeilnehmer").append(
$("<option>").val(i.toString()).html(i.toString())
);
}
}
Aspx, code behind:
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public static int GetAnzahlFreiePlaetze(int fuehrungId)
{
if (IsUserInRole(GlobalConstants.RoleAdmin))
{
return
AppGlobal.Repository<IConfigurationEntryRepository>()
.GetValue<int>(GlobalConstants.ConfigMaxTeilnehmerAdmin);
}
int res = AppGlobal.Repository<IAnzahlTeilnehmerRepository>().GetAnzahlFreiePlaetze(fuehrungId);
int max =
AppGlobal.Repository<IConfigurationEntryRepository>()
.GetValue<int>(GlobalConstants.ConfigMaxTeilnehmerUser) + 1;
if (res <= max)
{
return res;
}
return max;
}