2

i have a webpart and it has dropdownlist and gridview and i am using updatepanel around dropdown and gridview..in gridview i have a textbox as date picker..when i go on that page and click on textbox the date picker appears but as soon as i change item in dropdown which triggers postback the datepicker never comes back.

here is the jquery code i am using if i change this code the updatepanel simply doesnt work.

<script type="text/javascript">
     var $ = jQuery.noConflict();
     $(function () {
         $('input[id*="txtftrNeededBy"]').datepicker({ dateFormat: 'dd-M-y', changeMonth: true, minDate: 0 });
         $('input[id*="txtNeededBy"]').datepicker({ dateFormat: 'dd-M-y', changeMonth: true, minDate: 0 });
         $('input[id*="txtftrQty"]').autoNumeric({ aSep: '', vMax: '999999', vMin: '0', wEmpty: 'zero', mDec: null });
         $('input[id*="txtQty"]').autoNumeric({ aSep: '', vMax: '999999', vMin: '0', wEmpty: 'zero', mDec: null });

     });

</script>
3
  • Its because the event binding was lost after the partial postback. Try rebind them again upon postback.. Commented Dec 6, 2012 at 20:42
  • like how..can u put code here Commented Dec 6, 2012 at 20:44
  • Posted an answer. Try and let me know. Commented Dec 6, 2012 at 20:45

3 Answers 3

2

once an update panel does a async post back it wipes everything away. you need to rebind

<script type="text/javascript">    

$(function () {
     BindEvents();
 }); 


function BindEvents() {

           var $ = jQuery.noConflict();

             $('input[id*="txtftrNeededBy"]').datepicker({ dateFormat: 'dd-M-y', changeMonth: true, minDate: 0 });
             $('input[id*="txtNeededBy"]').datepicker({ dateFormat: 'dd-M-y', changeMonth: true, minDate: 0 });
             $('input[id*="txtftrQty"]').autoNumeric({ aSep: '', vMax: '999999', vMin: '0', wEmpty: 'zero', mDec: null });
             $('input[id*="txtQty"]').autoNumeric({ aSep: '', vMax: '999999', vMin: '0', wEmpty: 'zero', mDec: null });
        }
</script>

And in your update panel reload the jquery events again like this

 <asp:UpdatePanel>
      <ContentTemplate
           <script type="text/javascript">
                          Sys.Application.add_load(BindEvents);
           </script>

           <!-- your stuff in the update panel -->
      </ContentTemplate>
    </asp:UpdatePanel>
Sign up to request clarification or add additional context in comments.

2 Comments

Ok I've updated my solution try now, you need to bind events when page is loaded and again when the update panel is triggerd.
Rickey, Boriss & Tariq I am so sorry that i kept u guys for so long because of my silly mistake. for Quantity ive used autonumeric library and I forgot to include in my masterpage as this was a recent change and thats why on post back it was breaking up everything. Thanks to FireBug and you guys for sure..I really appreciate your time and efforts to solve this (finally) ..
0

This should work.

var $ = jQuery.noConflict();
$(document).ready(function(){
   BindEventHandler();
});
$.ajaxStop(function(){
   BindEventHandler();
});

function BindEventHandler(){
$('input[id*="txtftrNeededBy"]').datepicker({ dateFormat: 'dd-M-y', changeMonth: true, minDate: 0 });
         $('input[id*="txtNeededBy"]').datepicker({ dateFormat: 'dd-M-y', changeMonth: true, minDate: 0 });
         $('input[id*="txtftrQty"]').autoNumeric({ aSep: '', vMax: '999999', vMin: '0', wEmpty: 'zero', mDec: null });
         $('input[id*="txtQty"]').autoNumeric({ aSep: '', vMax: '999999', vMin: '0', wEmpty: 'zero', mDec: null });
}

13 Comments

Tariq this time updatepanel is working but on page load first time the datepicker appears but once again if i select any item from dropdown and click on datepicker it never comes
Try to call your function like this Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(BindEventHandler)
boriss where do i need to add this statement? in document.ready first line?
inside tag <script type="text/javascript"></script>together with function suggested Tariqulazam
Try to debug if the ajaxStop callback is fired or not after you select an item from the dropdown. Alternatively try what Boriss suggested.
|
0

Try it this way

$(function(){
     Sys.WebForms.PageRequestManager.getInstance().add_endRequest(BindEventHandler);
     BindEventHandler();
});

1 Comment

Sushanth after trying ur statement the datepicker is appearing as expected but updatepanel doesnt work on 2nd time item select..it only works on first time..this is what happening here..either one thing works jquery or updatepanel but not both together :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.