Search code examples
c#asp.netdatepickerdatetimepicker

How to get DateRangePicker control value in ASP.NET (C#)


When add (runat="server"), i can get control name "txtDate" but it diskplay like text input. When without runat="server", control working but i can't get control name to get value.

 <input type="text" name="daterange" id="txtDate" runat="server" value="01/01/2015 - 01/31/2015"/>
 <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
 <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

<script type="text/javascript">
  $(function() {
  $('input[name="daterange"]').daterangepicker();});
</script>

Code behind:

 protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = txtDate.Value;
    }

Solution

  • Since you have given the runat="server" the accessible id of that particular control from the script will change with respect to the page name/masterpage name if any. so that you have to access them Like the following in script:

     $("#<%=txtDate.ClientID%>").daterangepicker();});