2013-07-01 2 views
0

asp.net 달력 제어로 jquery를 사용하여 연도와 월을 변경하려하지만 올해를 변경할 수 없습니다. 캘린더 contorol 속성에 문제가있을 수 있습니다. jquery와 함께 Asp.Net의 일정 관리에서 날짜를 설정할 수 없습니다.

다음

당신은 jQuery를 통해 ASP.Net 달력에 VisibleDate 속성을 설정할 수 없습니다 내 코드

$(document).ready(function() { 

    var cyear = $('#<%=Ddyear.ClientID %>'); 
    var cmonth = $('#<%=Ddmonth.ClientID %>'); 

    var cal = $('#<%=Calendar1.ClientID %>'); 
    cyear.change(function() { 
     var item = cyear.val(); 
     var item2 = cmonth.val(); 

     item = item + ',' + item2; 
     $.ajax({ 
      type: "POST", 
      url: "dashboardQuery.aspx/calanderdates", 
      data: '{item:"' + item + '"}', 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: function (response) { 
       var sdate = Date.parse(response.d, "MM/dd/yyyy"); 
       dates = sdate; 
       $('#<%=Calendar1.ClientID %>').attr('VisibleDate', sDate); 
      }, 
      error: function() { 
       alert(msg.status); 
      } 
     }); 
    }); 
}); 

답변

0

, 그것은 생성 된 HTML에는 VisibleDate 재산이없는 등, 서버 측 속성입니다 .

당신은이 같은 작업 것 대신에 서버 측에서 날짜를 변경하는 코드를 변경할 수 있습니다 :

<asp:DropDown runat="server" ID="Ddmonth" OnSelectedIndexChanged="Ddmonth_SelectedIndexChanged" /> 

코드 숨김

protected sub Ddmonth_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    // depending on what is in your drop down list will affect this code 
    // this code assumes that you are listing the months by number, e.g. 1 for January, 2 for February, etc. 
    int selectedMonth = int.Parse(DdMonth.SelectedValue); 
    int monthsToAdd = selectedMonth - Calendar1.VisibleDate.Month; 
    Calendar1.VisibleDate = Calendar1.VisibleDate.AddMonths(monthsToAdd); 
} 
+0

안녕하세요 숀, 재생 주셔서 감사합니다. 나는 또한 $ ('# <% = Calendar1.ClientID %>')를 사용하여 클라이언트 제어를 잘 수행했다. attr ('VisibleDate', sDate); 하지만 여전히 작동하지 않습니다 – user2473112

+0

VisibleDate는 절대로 작동하지 않습니다. 이것은 클라이언트 측 속성이 아니며 서버 측 코드 내에 만 존재합니다. ' 컨트롤에 대한 마크 업을 게시 할 수 있습니까? – Sean

+0

나는 캘린더 컨트롤의 렌더링 된 마크 업을 살펴본 결과 왜 그만 사용했는지 기억하고있다. 무엇을 성취하려고합니까? 달력 컨트롤보다 융통성있는 것을 사용할 수도 있습니다. 날짜를 선택하는 데 방금 사용하는 경우 http://jqueryui.com/datepicker/ – Sean

관련 문제