Click here to Skip to main content
15,887,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Expert,

Working on asp.net Application.

I have used javascript for time picker control.Timepicker textbox is in update panel.

It works fines only for first time.And second time it does not work when i click any button or postback.

Please help me.


Here is my code

XML
<script type="text/javascript" language="javascript" src="Styles/Date Time Picker/prototype-1.js"></script>
<script type="text/javascript" language="javascript" src="Styles/Date Time Picker/behaviour.js"></script>
<script type="text/javascript" language="javascript" src="Styles/Date Time Picker/datepicker.js"></script>
<link rel="stylesheet" href="Styles/Date Time Picker/datepicker.css"/>
<script type="text/javascript" language="javascript" src="Styles/Date Time Picker/behaviors.js"></script>


<asp:UpdatePanel ID="UpdatePanel3" runat="server">
                                       <ContentTemplate>
<div>
 <asp:TextBox ID="txtArrivalTime1" class="timepicker" runat="server"
                  Width="285px"></asp:TextBox>


</ContentTemplate>
<Triggers>
    <asp:AsyncPostBackTrigger ControlID="chkAbv1" EventName="checkedchanged" />
     <asp:AsyncPostBackTrigger ControlID="chkAbv2" EventName="checkedchanged" />
     </Triggers>
     </asp:UpdatePanel>



please help me to solve this problem.

Thanks In adv & Sorry for poor English
Posted

1 solution

I would say that the time picker isn't reinitialized (it's basically a new element) after the asynchronous postback. I don't know how you initialize it, but I assume you're using $(document).ready now?

You should use the pageLoaded event, like so:
JavaScript
Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(function(evt, args) {
    $(".timepicker").datepicker(); // Or however you initialize the jQuery plugin.
});


Using that, you shouldn't need $(document).ready anymore. Here[^] is some more info on that.

As an alternative, you can create a custom control out of it (probably the nicest way to do it, more reusable). However, that might be a little bit too advanced.

More info on that:
Asp.Net Ajax ScriptControl Tutorial[^]
ASP.NET: Create AJAX Server Controls using the ScriptControl base class[^]
Adding Client Capabilities to a Web Server Control[^]
Creating Custom ASP.NET AJAX Client Controls—IScriptControl.GetScriptDescriptors Method[^]
 
Share this answer
 
Comments
udusat13 5-Aug-13 7:58am    
Thanks For reply.

This is the only code i am using.

Above mentioned Javascript file and class="timepicker" for textbox(timepicker textbox).
Kim Dobranski 16-Mar-21 22:11pm    
This works like a charm. Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900