0

The following code works perfectly fine if i don't use update panels in my aspx page:

<script src="../Scripts/jquery-1.10.2.min.js"></script>
<link href="../Css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<script src="../Scripts/bootstrap-datetimepicker.js"></script>
<script type="text/javascript">

    $("#<%=txtFromDate.ClientID%>").datetimepicker({
        format: 'yyyy-mm-dd',
        language: 'us',
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0
    });
</script>

So i wanted to use update panel because i want to show a loading icon via UpdateProgress tag. So someone suggested that i should use this code :

<script src="../Scripts/jquery-1.10.2.min.js"></script>
<link href="../Css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<script src="../Scripts/bootstrap-datetimepicker.js"></script>
<script type="text/javascript">

    var prm = Sys.WebForms.PageRequestManager.getInstance();

    if (prm != null) {
        prm.add_endRequest(function (sender, e) {
            if (sender._postBackSettings.panelsToUpdate != null) {
                $("#<%=txtFromDate.ClientID%>").datetimepicker({
                    format: 'yyyy-mm-dd',
                    language: 'us',
                    weekStart: 1,
                    todayBtn: 1,
                    autoclose: 1,
                    todayHighlight: 1,
                    startView: 2,
                    minView: 2,
                    forceParse: 0
                });    
            }
        }
    );

</script>

If i use this code i get an error that says Object doesn't support property or method 'datetimepicker' on this line : $("#<%=txtFromDate.ClientID%>").datetimepicker({

What could be the possible cause ?

enter image description here

wazz
  • 4,953
  • 5
  • 20
  • 34
chosenOne Thabs
  • 1,480
  • 3
  • 21
  • 39
  • Have you tried using ASP.NET's script manager? It should be as easy as registering it in your page/masterpage depending on your setup. You can find it in the toolbox. – Martin Jun 20 '18 at 01:08
  • I don't know if this will solve it, but you have a parenthesis at the end instead of a brace. Or is that just a typo? -- edit -- Nvmnd, I see it's correct in the img. – wazz Jun 20 '18 at 03:07
  • @Martin - the script manager is included already. – chosenOne Thabs Jun 20 '18 at 20:52
  • @Wazz - i removed the parenthesis, and the issue still persisted – chosenOne Thabs Jun 20 '18 at 20:52

1 Answers1

2

If your goal is to show the UpdateProgress control, you can probably do away with all of that and go back to your original code. If you trigger an async postback (inside the update panel, or outside), the UpdateProgress control will fire automatically, and it (the UpdateProgress control) can be anywhere on the page, even outside the update panel!

If the UpdateProgress control is not associated with a specific update panel it will fire for all async postbacks.

Note, if the async postback is really fast, you might not see the UpdateProgress control. If it takes a second or two, it should show up.

Hth.

wazz
  • 4,953
  • 5
  • 20
  • 34
  • 1
    Thank you for the suggestion Wazz. I moved updatepanels(from date textbox) to a different location in the html. The code is working fine. – chosenOne Thabs Jun 20 '18 at 20:54