Search code examples
asp.netvisual-studiodatepicker

Date Picker in Asp.net doesn't appear


I make 2 datepicker but only 1 show the table of date when I run it

<div class="form-group left">
                                <label for="invoicedate" class="label-title"> Invoice Date : </label>
                                <asp:TextBox ID="txtDate" runat="server" class="form-input" required="required" ReadOnly="true"  placeholder="mm/dd/yyyy" OnClick="Datebtn_Click"></asp:TextBox>
                            </div>
<div class="form-group left">
                                <label for="shipmentdate" class="label-title"> Shipment Date : </label>
                                 <asp:TextBox ID="textDate" runat="server" class="form-input" required="required" ReadOnly="true"  placeholder="mm/dd/yyyy" OnClick="Addbtn_Click"></asp:TextBox>
                            </div>

The code behind

protected void Datebtn_Click(object sender, EventArgs e)
        {
            string dt = Request.Form[txtDate.UniqueID];
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Selected Date:" + dt + "'); ", true);
        }

        protected void Addbtn_Click(object sender, EventArgs e)
        {
            string dt = Request.Form[txtDate.UniqueID];
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Selected Date:" + dt + "'); ", true);
        }

Script code

<script type="text/javascript">
    $(function () {
        $('[id*=txtDate]').datepicker({
            changeMonth: true,
            changeYear: true,
            format: "dd/mm/yyyy",
            language: "tr"
        });
    });
</script>

It doesn't show any error when I run it. Can anyone help me


Solution

  • Because you created two textboxes with different Ids, one with "txtDate" and another with "textDate".

    For Addbtn_Click: id should be changed to: "textDate.UniqueID"

    There is only txtDate in the script.

    After all corresponding modifications are made, then both should be able to work.