Question

My application is in asp.net 3.5 in which i am selecting date from date picker which is inside update panel. after selecting date and clicking on submit button page is post back. after post back when i try to select date once again i can`t see date picker there.

//Code on aspx page

 <%@ Page Title="" Language="C#" MasterPageFile="~/Sample/MasterPage.master" AutoEventWireup="true" CodeFile="UpdateProblem.aspx.cs" Inherits="Sample_UpdateProblem" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script type="text/javascript" src="jscolor/jscolor.js"></script>  // Script for date 
<asp:ScriptManager ID="ScriptManager1" runat="server" >
</asp:ScriptManager>
<div>
<asp:UpdatePanel ID="panel1" runat="server">
    <ContentTemplate>
        <asp:TextBox runat="server" ID="textbox" CssClass="color" />
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Content>

Thanks in advance

Was it helpful?

Solution

In your UpdatePanel add css class on your test box

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
           <asp:TextBox ID="TextBox1" runat="server" CssClass="classTarget"></asp:TextBox>
           ..... 
        </ContentTemplate>
</asp:UpdatePanel>

In your script add this code

   <script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.js">
   </script>
   <script type="text/javascript">
        $(document).ready(function() {
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

            function EndRequestHandler(sender, args) {
                $('.classTarget).datepicker({ dateFormat: 'dd-mm-yy' });
            }

        });
    </script>   

OTHER TIPS

$(function () {
   bindDatePickers(); // bind date picker on first page load
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindDatePickers); // bind date picker on every UpdatePanel refresh
});

function bindDatePickers() {
   $('#<%= txtInvoiceDateFrom.ClientID%>').datepicker({
      uiLibrary: 'bootstrap4'
   });
   $('#<%= txtInvoiceDateTo.ClientID%>').datepicker({
      uiLibrary: 'bootstrap4'
   });
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top