I have to give textbox control id like below
<asp:TextBox ID="7_1" runat="server">
It is not allowing me. If I give
<asp:TextBox ID="Test7_1" runat="server">
Then it works fine. Why? Why can not give start with numbers?
I have to give textbox control id like below
<asp:TextBox ID="7_1" runat="server">
It is not allowing me. If I give
<asp:TextBox ID="Test7_1" runat="server">
Then it works fine. Why? Why can not give start with numbers?
Because in .NET variable names cannot start with a number. Neither an id in HTML by the way. So when Visual Studio tries to generate a .designer file from the aspx page it chokes because this is invalid:
protected TextBox 7_1;
it simply cannot compile.
It's a restriction of the common language specification that no identifiers can start with numbers. The textbox you define in the markup is also created in the designer.cs file as a TextBox object. This coded object reference gets the same name as the markup ID, and thus the restriction.
Valid variable names must start with a letter. This is enforced by the compiler. The codebehind creates a variable that matches your textbox, this allows you to access said textbox and it's properties in said codebehind. Therefore, you are not allowed to have invalid names on your elements.