Difference between revisions of "Jquery"

From no name for this wiki
Jump to: navigation, search
(JQuery)
(JQuery)
 
Line 1: Line 1:
 
== JQuery ==
 
== JQuery ==
 
+
Dropdowninhalt anhand anderem Dropdown auffüllen:
 
<source lang="javascript">
 
<source lang="javascript">
 
   $(function () {
 
   $(function () {
Line 49: Line 49:
 
</source>
 
</source>
  
 +
Aspx, code behind:
  
 
<source lang="csharp">
 
<source lang="csharp">

Latest revision as of 16:47, 22 March 2013

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;            
        }