datepicker value is blank when disabled, jquery
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开发者_StackOverflow中文版="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.
Just a guess, but try using READONLY instead of DISABLED?
I think also using readonly property to true, does not change the intial value in postback
if are insist to use it by readonly property you will change override of get Text like this
public override string Text
{
get
{
if (!base.ReadOnly)
return base.Text;
string s = HttpContext.Current.Request.Params[this.UniqueID];
if (s == null)
return base.Text;
else
{
base.Text = s;
return s;
}
}
set
{
base.Text = value;
}
}
Regards
This code worked for me
$('input:checkbox[name=cmpltInd]').change(function () {
if ($(this).is(':checked')) {
$('#efctDt').attr('readonly', true).datepicker("option", "showOn", "off");
}
else {
$('#efctDt').attr('readonly', false).datepicker("option", "showOn", "focus");
}
});
if ( ($('input:checkbox[name=cmpltInd]') != "undefined") && ($('input:checkbox[name=cmpltInd]').prop("checked")== true)) {
$('#efctDt').attr('readonly', true).datepicker("option", "showOn", "off");
}
精彩评论