views:

366

answers:

2

whats wrong with the below code, its throwing me an error of Compiler Error Message: CS1002: ; expected

    $(document).ready(function() {

      $('<%=StartDate.UniqueID%>').datepicker({ showOn: 'button',
          buttonImage: '../images/Calendar.png',
          buttonImageOnly: true, onSelect:
                function() { },
          onClose: function() { $(this).focus(); }
      }); 
    });

<label for="sd">StartDate:</label>
    <asp:TextBox ID="StartDate" runat="server"></asp:TextBox>

error

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). 
+2  A: 

Maybe this:

<div runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            $('#<%=StartDate.ClientID%>').datepicker({ showOn: 'button',
                    buttonImage: '../images/Calendar.png',
                    buttonImageOnly: true, onSelect: function () { },
                    onClose: function () { $(this).focus(); }
            });
        });
    </script>
</div>
Unlimited071
i tried with both ClientID and also UniqueIdgetting this error: i have updated my code above
Abu Hamzah
are you trying to insert some control dynamically? if your trying to do that then I think you should use a placeholder control and create/insert your control in there.
Unlimited071
i just have a plain web form with all reference in it and just trying to have a datepicker on asp.net control, very simple.
Abu Hamzah
if your script tag is in the body try nesting it inside a div tag with a runat attribute. I was doing some searching and it seems this can solve the problem, don't know why though.
Unlimited071
here is the error message i am getting:"Microsoft JScript runtime error: Object doesn't support this property or method"
Abu Hamzah
+2  A: 

the reason i was getting the error:

"Microsoft JScript runtime error: Object doesn't support this property or method"

because of i was havign conflict .js reference and there were two different set of .js was on the page

hope this helps other.

Abu Hamzah
Thanks for the answer, this saved me a bunch of time. I am using Telerik MVC menu and had a script block on the page that was referencing the jquery-1.4.2.min also so I had two references.
RJ