locked
Set values from code behind RRS feed

  • Question

  • User-284642143 posted
    <asp:UpdatePanel ID="upanel1" runat="server">
    	<ContentTemplate>
    		<div id="mdp-demo"></div>
    	</ContentTemplate>
    </asp:UpdatePanel>
    
        <script>
            var date = new Date();
            $('#mdp-demo').multiDatesPicker({
                dateFormat: "d-m-y"
            });
    		
            $(function () {
                $("#btnAdd").click(function () {
                    debugger;
                    var dates = $('#mdp-demo').multiDatesPicker('getDates');
                    $("#hiddenField1").val(dates);
                })
            })
    
            $(document).ready(function () {
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    
                function EndRequestHandler(sender, args) {
                    $('#mdp-demo').datepicker({ dateFormat: 'd-m-y' });
                }
    			
    			$("#btnAdd").click(function () {
                  
                    var dates = $('#mdp-demo').multiDatesPicker('getDates');
                    $("#HiddenField1").val(dates);
    				
    			// Add code to set dates
    			var setdates = <%=this.setdates %>;
    			$('#mdp-demo').multiDatesPicker('addDates', setdates);
            });
    
        </script>

    Im trying to set dates for this control via code behind. My current attempt (Add code to set dates) is having setdates to call a variable in code behind but i get a "circular error". The addDates function allows me to add dates so not sure what im missing here?

    Friday, September 28, 2018 2:31 PM

All replies

  • User-271186128 posted

    Hi EssCee,

    Im trying to set dates for this control via code behind. My current attempt (Add code to set dates) is having setdates to call a variable in code behind but i get a "circular error". The addDates function allows me to add dates so not sure what im missing here?

    Please refer to the following code to get the date variable in the code behind:

    Code behind:

            public DateTime setdates;
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    setdates = DateTime.Now;
                }
            }

    Code in the .aspx page: need to add the quotation marks

                $("#btnAdd").click(function () {
    
                    var dates = $('#mdp-demo').multiDatesPicker('getDates');
                    $("#HiddenField1").val(dates);
                    //debugger;
                    // Add code to set dates
                    var setdates = '<%=this.setdates %>';
                    $('#mdp-demo').multiDatesPicker('addDates', setdates);
                });

    More details about how to use MultiDatesPicker please refer to the following link:

    http://dubrox.github.io/Multiple-Dates-Picker-for-jQuery-UI/#method-getDates

    Best regards,
    Dillion

    Monday, October 1, 2018 6:02 AM