I am trying to get the client name of a control so I can use a jqueryUI function on it.
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" ShowFooter="True"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Date">
<FooterTemplate>
<asp:TextBox ID="DateField" runat="server"></asp:TextBox>
<script type="text/javascript">
$(document).ready(function () {
$('#<%=DateField.ClientID %>').datepicker();
});
</script>
</FooterTemplate>
I get an error message
CS0103: The name 'DateField' does not exist in the current context
Now according to some of the other post, the issue is that the field is not registered in the designer. Currently the only two fields registered in the designer are form1 and GridView1. If I attempt to add the field manually I get the error
Object reference not set to an instance of an object.
Which makes sense in a way. I geuss the question is how are form1 and Gridview1 being initialized. Also now if I make any modifications to the page my variable disappears.
So what is the correct way to wireup a datepicker to a textbox inside a grid?
Note I have moved my script block from the header, to the end, to inside the template field all with no change.
and in script