datepicker value is blank when disabled, jquery

Posted by Mithil Deshmukh on Stack Overflow See other posts from Stack Overflow or by Mithil Deshmukh
Published on 2010-06-08T22:08:34Z Indexed on 2010/06/08 22:12 UTC
Read the original article Hit count: 309

Filed under:
|

Hi. I'm fairly new to jQuery. I have a Jquery datepicker in a user control. I have added a "disable" property to the datepicker. Whenever I save the page(having this usercontrol) the datepicker with disable set to true is empty. All other datepickers save fine.

Here is my code.

ASPX

< USERCONTROL:DATEPICKER id="dpBirthDate" startyear="1980" runat="server" Disable=true>

ASCX < input type="text" size="8" runat="server" id="txtDate" name="txtDate" onblur="ValidateForm(this.id);" />

ASCX Code Behind

Public Property Disable() As Boolean Get Return (txtDate.Disabled = True) End Get Set(ByVal bValue As Boolean)

            If (bValue = True) Then
                txtDate.Attributes.Add("Disabled", "True")
            Else
                txtDate.Attributes.Remove("Disabled")
            End If

        End Set


    End Property

My Jquery $(document).ready(function() {

    $("input[id$=txtDate]").datepicker({ showOn: 'button', buttonImage: '<%=ConfigurationSettings.AppSettings("BASE_DIRECTORY")%>/Images/el-calendar.gif', buttonImageOnly: true });
    $("input[id$=txtDate]").mask("99/99/9999", { placeholder: " " });


    //Disable datepicker if "disable=true"
    $("input[id$=txtDate]").each(function() {

    if ($("input[id$=" + this.id + "]").attr("Disabled") == "True") {          
            $("input[id$=" + this.id + "]").datepicker("disable");               
        }
        else if ($("input[id$=" + this.id + "]").attr("Disabled") == "False") {
            $("input[id$=" + this.id + "]").datepicker("enable");
        }

    });


});

I am sorry, I am not sure how to format the code here. I apologies for the cluttered code. Can anybody tell me why the datepicker value is empty when it is disabled but works fine otherwise? Thanks is advance.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about datepicker