Datepicker does not display when I load data with a C # search, Bootstrap. ASP NET

0

I have a problem I'm making a page in which when the charge is a search button, I enter a data and I load several textbox. The question is that one of the textbox I use to load a date manually, it is disabled when the data is loaded here is the ASP code

    

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <div class="page-title">
            <table style="width: 100%">
                <tr>
                    <td style="width: 30%"></td>
                    <td style="width: 45%; text-align: center">
                        <div>
                            <h4>
                                <p class="description">
                                    <asp:Label ID="lbltipo" runat="server" Text="Contrato-Cronograma"></asp:Label>
                                </p>
                                <h4></h4>
                                <h4></h4>
                                <h4></h4>
                                <h4></h4>
                                <h4></h4>
                                <h4></h4>
                            </h4>
                        </div>
                    </td>
                    <td style="width: 25%">
                        <div class="title-env2">
                    <h4>

                    </h4>
                </div>


                    </td>
                </tr>
            </table>

        </div>

        <div class="panel panel-default">

            <div class="panel-body">

                <div role="form" class="form-horizontal">
                      <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_numRegistroConstruccion">Registro Construccion </label>

                        <div class="col-sm-10">
                            <asp:TextBox ID="txt_numRegistroConstruccion" runat="server" ></asp:TextBox>
                                    <ajaxToolkit:AutoCompleteExtender ID="acompleteRegistro" runat="server" DelimiterCharacters="" Enabled="True" TargetControlID="txt_numRegistroConstruccion" ServiceMethod="GetCliente"
                                        MinimumPrefixLength="1" ServicePath="~/Autocomplete.asmx" CompletionInterval="200">
                                    </ajaxToolkit:AutoCompleteExtender>
                             <asp:Button ID="btn_buscar" runat="server" CssClass="btn2 btn-success" Text="Buscar" OnClick="btn_buscar_Click" />
                        </div>
                    </div>
                         <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_numContrato">Contrato #</label>

                        <div class="col-sm-10">
                            <asp:Label ID="txt_numContrato" runat="server" class="form-control" ></asp:Label>
                        </div>
                    </div>
                         <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_idCliente">Id. Cliente</label>

                        <div class="col-sm-10">
                            <asp:Label ID="txt_idCliente" runat="server" class="form-control" ></asp:Label>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_nombres">Nombres</label>

                        <div class="col-sm-10">
                            <asp:Label ID="txt_nombres" runat="server" class="form-control" ></asp:Label>
                        </div>
                    </div>
                      <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_cedula">Cedula</label>

                        <div class="col-sm-10">
                            <asp:Label ID="txt_cedula" runat="server" class="form-control" ></asp:Label>
                        </div>
                    </div>

                     <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_numPisos">Num. pisos</label>

                        <div class="col-sm-10">
                            <asp:Label ID="txt_numPisos" runat="server" class="form-control" ></asp:Label>
                        </div>
                    </div>

                     <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_areaConstruccion">Area construccion(m2)</label>

                        <div class="col-sm-10">
                            <asp:Label ID="txt_areaConstruccion" runat="server" class="form-control" ></asp:Label>
                        </div>
                    </div>
                     <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_fecCaducidad">Fec. Caducidad</label>

                        <div class="col-sm-10">
                            <asp:Label ID="txt_fecCaducidad" runat="server" class="form-control" ></asp:Label>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="ddnivelFedatario">Nivel Construccion:</label>
                        <div class="col-sm-10">
                            <asp:Label ID="ddnivelFedatario" runat="server" class="form-control" ></asp:Label>
                        </div>

                    </div>
                     <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_idFedatario">Id Fedatario:</label>

                        <div class="col-sm-10">
                            <asp:Label ID="txt_idFedatario" runat="server" class="form-control" ></asp:Label>
                        </div>
                    </div>
                        <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_Fedatario">Fedatario asignado:</label>

                        <div class="col-sm-10">
                            <asp:Label ID="txt_Fedatario" runat="server" class="form-control" ></asp:Label>
                        </div>
                    </div>
                        <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_visitasBase">Visitas Base</label>

                        <div class="col-sm-10">
                            <asp:Label ID="txt_visitasBase" runat="server" class="form-control"></asp:Label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_visitasAdicionales">Visitas adicionales</label>

                        <div class="col-sm-10">
                            <asp:Label ID="txt_visitasAdicionales" runat="server" class="form-control"></asp:Label>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_observaciones">Observaciones</label>

                        <div class="col-sm-10">

                            <asp:Label ID="txt_observaciones" runat="server" class="form-control"></asp:Label>

                        </div>

                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label" for="txt_fecha">Fecha </label>

                        <div class="col-sm-10">
                            <asp:TextBox ID="txt_fecha" runat="server" class="form-control datepicker" data-format="dd/mm/yyyy"></asp:TextBox>
                        </div>
                    </div>
                    <br />

                  <asp:GridView ID="gv_lista" runat="server" Width="100%" AutoGenerateColumns="false" class="table table-striped table-bordered">
                   <Columns>


                   </Columns>

                                        </asp:GridView>
                </div>
            </div>





            <br />
            <asp:Button CssClass="btn btn-success btn-icon" ID="btn_guardar" runat="server" Text="GUARDAR" Style="width: 100%; height: 30px" OnClick="btn_guardar_Click" />
            <br />                         

            <br />
            <asp:Button CssClass="btn btn-success btn-icon" ID="btn_cancelar" runat="server" Text="CANCELAR" Style="width: 100%; height: 30px" OnClick="btn_cancelar_Click" />
            <br />
            <br />
        </div>

    </ContentTemplate>
</asp:UpdatePanel>


<script type="text/javascript">

    function showAjaxModal(tit, val) {
        jQuery('#modal-7 .modal-body').html(val);
        jQuery('#modal-7 .modal-header .modal-title').html('<p>' + tit + ' </p>');
        jQuery('#modal-7').modal('show', { backdrop: 'static' });
    }

</script>

                                                      

and this the search button code

protected void btn_buscar_Click (object sender, EventArgs e)     {         DataTable dat = new DataTable ();         int registrationConstruction = int.Parse (txt_numRegistroConstruccion.Text.ToString ());

    dat = contra.ll_cargaContrato(registroConstruccion, idempresa);



    if (dat.Rows.Count != 0)
    {
        try
        {
            txt_idCliente.Text = dat.Rows[0][0].ToString();
            txt_nombres.Text = dat.Rows[0][1].ToString();
            txt_cedula.Text = dat.Rows[0][2].ToString();
            //txt_direccion.Text = dat.Rows[0][3].ToString();
            //txt_correo.Text = dat.Rows[0][4].ToString();
            //txt_telefono.Text = dat.Rows[0][5].ToString();
            txt_numContrato.Text =  dat.Rows[0][6].ToString();
            // txt_registroConstruccion.Text = dat.Rows[0][7].ToString();
            txt_numPisos.Text = dat.Rows[0][8].ToString();
            txt_areaConstruccion.Text = dat.Rows[0][9].ToString();
            txt_fecCaducidad.Text = dat.Rows[0][10].ToString();
            //txt_tecnico.Text = dat.Rows[0][11].ToString();
            //txt_emailTecnico.Text = dat.Rows[0][12].ToString();
            //txt_fonoTecnico.Text = dat.Rows[0][13].ToString();
            txt_visitasAdicionales.Text = dat.Rows[0][14].ToString();
            txt_idFedatario.Text= dat.Rows[0][15].ToString();
            ddnivelFedatario.Text = dat.Rows[0][16].ToString();
            txt_visitasBase.Text = dat.Rows[0][17].ToString();
            txt_observaciones.Text = dat.Rows[0][18].ToString();
            txt_Fedatario.Text = dat.Rows[0][19].ToString();

            int numFilas = int.Parse(dat.Rows[0][17].ToString()) + int.Parse(dat.Rows[0][14].ToString());


             DataTable dat1 = new DataTable();



             dat1.Columns.Add("ID");
            dat1.Columns.Add("Fase", Type.GetType("System.String"));
            dat1.Columns.Add("Fecha", Type.GetType("System.String"));
            dat1.Columns.Add("Observaciones", Type.GetType("System.String"));

            Session["DT"] = dat1;


            int contador = 0;
                      for (int i = 1; i <= numFilas; i++)
                      {


                          foreach (DataColumn colum in dat1.Columns)
                          {
                              DataRow dr = dat1.NewRow();
                              dr["Id"] = i;
                              //dr["Fecha"] = "Responsable " + contador.ToString();
                              //dr["Comentarios"] = "Analista " + contador.ToString();

                              dat1.Rows.Add(dr);
                              contador++;
                          }

                      }
                gv_lista.DataSource = dat1;

               gv_lista.DataBind(); 
        }
        catch (Exception ex) { Response.Redirect("apl6.aspx"); }

    }


    //gv_lista.DataBind();
}

I would appreciate very much helping me with this error that occurs, because if I do not do the search data caarga, there if the datepicker is presented without problems

    
asked by Ing Marcelo Rodriguez 27.05.2018 в 09:23
source

1 answer

0

I think the problem is that, after the post, the UpdatePanel deletes all the HTML elements and recreates them, then the datepicker is deleted. Surely you are creating the datepicker through JavaScript with a DatePicker library for Bootstrap, right? If so, after updates to the UpdatePanel you should re-create the datepicker, for example, adding this script to the bottom of the page:

<script type="text/javascript">
    var requestManager = Sys.WebForms.PageRequestManager.getInstance();
    requestManager.add_endRequest(function () { $('.datepicker').datepicker(); });
</script>

If you create the datepicker in another way you should only change the "$ ('. datepicker'). datepicker ();" for what you use to create it.

I hope it serves you.

Good luck!

    
answered by 27.10.2018 в 01:44