简体   繁体   中英

Why does my javascript function only work once calling from codebehind?

I'm trying to show the exam dates and times on the calendar. I'm switching from Javascript to codebehind. But even though my function is in the for loop, it only brings an event. I have three exam dates in my database. But one comes. (I m using asp.net,c#,javascript and html.)

I'd appreciate it if you helped.

Codebehind..

for (int i = 0; i < dt1.Rows.Count; i++)
{

//parameter create and assign

 ScriptManager.RegisterStartupScript(this, typeof(Page), "displayalertmessage", "helloFromCodeBehind('" + dt1.Rows[i]["description"] + "','" + dt1.Rows[i]["title"] + "','" + a + "','" + k1 + "','" + a2 + "','" + a3 + "','" + a4 + "','" + b + "','" + k2 + "','" + b2 + "','" + b3 + "','" + b4 + "')", true);


}

my html code...

    <div class="panel-body">
        <div id="calendar" class="has-toolbar"></div>
    </div>

my javascript code...

function helloFromCodeBehind(description, title1, gun, ay, yil, saat, saat2, gun3, ay3, yil3, saat3, saat4) {
  if (jQuery().fullCalendar) {

    var e = new Date,
      t = e.getDate(),
      a = e.getMonth(),
      n = e.getFullYear(),
      r = {};

    $("#calendar").removeClass("mobile"), r = {
      left: "prev,next,today",
      center: "title",
      right: "month,agendaWeek,agendaDay"
    };
    var l = function(e) {
        var t = {
          title: $.trim(e.text())
        };
        e.data("eventObject", t), e.draggable({
          //zIndex: 999,
          //revert: !0,
          //revertDuration: 0
        })
      },
      o = function(e) {
        e = 0 === e.length ? "Untitled Event" : e;
        /* var t = $('<div class="external-event label label-event">' + e + "</div>");*/
        var t = $('<div class="external-event label label-event-' + e + '">' + e + "</div>");
        jQuery("#event_box").append(t), l(t)
      };
    $("#external-events div.external-event").each(function() {
        l($(this))
      }),
      $("#event_add").unbind("click").click(function() {
        var e = $("#event_title").val();
        o(e)
      }),
      $("#event_box").html(""), o("holiday"), o("birthday"), o("meeting"), o("competition"), o("dinner"), o("party"), $("#calendar").fullCalendar("destroy"), $("#calendar").fullCalendar({
        header: r,
        defaultView: "month",

        slotMinutes: 15,
        //editable: !0,
        //droppable: !0,
        //drop: function(e, t) {
        //    var a = $(this).data("eventObject"),
        //        n = $.extend({}, a);
        //    n.start = e, n.allDay = t, n.className = $(this).attr("data-class"), $("#calendar").fullCalendar("renderEvent", n, !0), $("#drop-remove").is(":checked") && $(this).remove()
        //},

        /***** events ********/


        events: [{
          title: title1,
          start: new Date(yil, ay, gun, saat, saat2),
          end: new Date(yil3, ay3, gun3, saat3, saat4),
          backgroundColor: "#DC35A9",
          allDay: !1
        }]
      })
  }

}

Looks like it symply overrides your function and the last one is called. Try this:

for (int i = 0; i < dt1.Rows.Count; i++)
{

//parameter create and assign

 ScriptManager.RegisterStartupScript(this, typeof(Page), "displayalertmessage"+i, "helloFromCodeBehind"+i+"('" + dt1.Rows[i]["description"] + "','" + dt1.Rows[i]["title"] + "','" + a + "','" + k1 + "','" + a2 + "','" + a3 + "','" + a4 + "','" + b + "','" + k2 + "','" + b2 + "','" + b3 + "','" + b4 + "')", true);


}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM