jQuery datepicker in asp:UpdatePanel
When using asp:UpdatePanel and jQuery datePicker function in the ui library, there is a need to register an event handler on the textbox/input field used to bind the datepicker in order to initialize the datepicker again.
If you are using a Custom User Control where you do not know if you have a page with update panel you can use the following method to look in the page for the update panel
VB.NET
When finding UpdatePanel in you page, you will have to register an event handler for your PageRequestManager in order to notify when an async request is made and completed.
In your code behind register a startup script:
On your page you can have a javascript function that initilize the datepicker on load of update is complete. If you have multiple textboxes the following script will do the trick:
If you have a asp:*Validator on your input textbox you will need to override the onSelect function within your datepicker:
Hope this will be of any help if you are using jQuery datepicker in update panel
If you are using a Custom User Control where you do not know if you have a page with update panel you can use the following method to look in the page for the update panel
VB.NET
- PublicShared Function FindCondtrolOfType(ByVal controls As List(Of Control), ByVal t As Type, ByVal parentControl As Control) As List(Of Control)
- For Each c As Control In parentControl.Controls
- If c.GetType().Equals(t) Then
- controls.Add(c)
- End If
- If c.HasControls Then
- controls =FindCondtrolOfType(controls, t, c)
- End If
- Next
- Return controls
- End Function
When finding UpdatePanel in you page, you will have to register an event handler for your PageRequestManager in order to notify when an async request is made and completed.
In your code behind register a startup script:
- Dim tScript As String = "$(function(){ Sys.WebForms.PageRequestManager.getInstance().add_endRequest([Your Method to call]); });"
- Page.ClientScript.RegisterStartupScript(Me.GetType(), "async_" & Me.[Your Text Box Name].ClientID, tScript, True)
On your page you can have a javascript function that initilize the datepicker on load of update is complete. If you have multiple textboxes the following script will do the trick:
- function showDatePicker(sender, args)
- {
- $('input[id$="[your input control"]').each(function()
- {
- $(this).datepicker({ showOn: 'focus' });
- });
- }
If you have a asp:*Validator on your input textbox you will need to override the onSelect function within your datepicker:
- onSelect: function() { 'any method/function' }
Hope this will be of any help if you are using jQuery datepicker in update panel
Comments