2011-10-19 19 views
8
<script type="text/javascript"> 
     $(function() { 
      $('.datePicker').datetimepicker({ dateFormat: 'dd/mm/yy' }); 
     }); 
    </script> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server"> 
    <asp:ScriptManager ID="ScriptManager1" runat="server"> 
    </asp:ScriptManager> 
    <asp:TextBox ID="TextBox1" class="datePicker" runat="server"></asp:TextBox> 
    <asp:UpdatePanel ID="holder" runat="server" UpdateMode="Always" ChildrenAsTriggers="true"> 
     <ContentTemplate> 
      <asp:DropDownList runat="server" ID="ddl_RespondBy" AutoPostBack="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged"> 
       <asp:ListItem Selected="True">1 Hour</asp:ListItem> 
       <asp:ListItem>Other</asp:ListItem> 
      </asp:DropDownList> 
      <asp:TextBox ID="txt_RespondBy" class="datePicker" Visible="true" runat="server" /> 
     </ContentTemplate> 
     <Triggers> 
      <asp:AsyncPostBackTrigger ControlID="ddl_RespondBy" EventName="SelectedIndexChanged" /> 
     </Triggers> 
    </asp:UpdatePanel> 
</asp:Content> 

protected void ddl_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     if (ddl_RespondBy.SelectedItem.Text == "Other") 
     { 
      txt_RespondBy.Visible = true; 
     } 
     else 
     { 

     } 
    } 

मैं अद्यतन पैनल के साथ वापस, मैं है आंशिक पोस्ट कर दो पाठ बॉक्स एक बाहर अद्यतन पैनल और एक के अंदर है, जब मैं ड्रॉप-डाउन से अन्य का चयन करें और करने की कोशिश txt_RespondBy टेक्स्ट बॉक्स के अंदर कैलेंडर खोलें जो यह प्रदर्शित नहीं होता है, लेकिन अपडेट पैनल के बाहर टेक्स्ट बॉक्स कैलेंडर दिखाता है। क्यों जावास्क्रिप्ट आंशिक पोस्टबैक के बाद अंदर अद्यतन पैनल काम नहीं कर रहाजावास्क्रिप्ट आंशिक पोस्टबैक के बाद काम नहीं करता है

उत्तर

13

प्लेस अपने DateTimePicker initialisation कोड जब भी पृष्ठ लोड (अतुल्यकालिक रूप से या तुल्यकालिक)।

<script type="text/javascript"> 
    function pageLoad(sender, args) { 
     $('.datePicker').datetimepicker({ dateFormat: 'dd/mm/yy' }); 
    }  
</script> 
+0

हाँ, अब काम करता है। धन्यवाद – Mark

2

आप उपयोग कर सकते हैं pageLoad या .live:

संदर्भ जानकारी: $(document).ready() and pageLoad() are not the same

.live:

Jquery .live works but not with .datepicker

$(function(){ 
    $('.datePicker').live('click', function() { 
     $(this).datepicker({showOn:'focus'}).focus(); 
    }); 
}); 

Pageload(): Pageload समारोह है, जो कहा जाता है में

function pageLoad(sender, args) { 
    $('.datePicker').datetimepicker({ dateFormat: 'dd/mm/yy' }); 
}  
+0

दोनों ने कोशिश की लेकिन यह काम नहीं कर रहा है ... –