Search code examples
javascriptasp.netdhtml

dhtml calendar not triggering in asp.net


I'm using jcal2 calendar for choosing date from calender. It working when i'm using

<input type="text" id="txtDob" >&nbsp;<img
                src="images/Calendar.png" width="25" height="22" id="f_btn1" />

            <script type="text/javascript">//<![CDATA[
                                            Calendar.setup({
                                                inputField :"txtDob",trigger:"f_btn1",onSelect:function(){this.hide()},showTime:12,dateFormat:"%d-%m-%Y"
                                            });//]]>
            </script>

But, not working in this case

<asp:TextBox ID="txtDob" Enabled="false" runat="server"></asp:TextBox> &nbsp;<img
                src="images/Calendar.png" width="25" height="22" id="f_btn1" />

            <script type="text/javascript">//<![CDATA[
                                            Calendar.setup({
                                                inputField :"txtDob",trigger:"f_btn1",onSelect:function(){this.hide()},showTime:12,dateFormat:"%d-%m-%Y"
                                            });//]]>
            </script>

Need help !!


Solution

  • You are passing Server Id of <asp:TextBox> control. You should use Client ID in your javascript.

    <asp:TextBox ID="txtDob" Enabled="false" runat="server"></asp:TextBox> &nbsp;<img
                    src="images/Calendar.png" width="25" height="22" id="f_btn1" />    
    <script type="text/javascript">//<![CDATA[
                    Calendar.setup({
                             inputField :"<%= txtDob.ClientID %>", 
                             trigger:"f_btn1",onSelect:function(){this.hide()},showTime:12,dateFormat:"%d-%m-%Y"
                                  });//]]>
    </script>