tags:

views:

36

answers:

4

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?

+2  A: 

standards say id's have to start with a letter.

see here: http://www.w3schools.com/tags/att_standard_id.asp

Patricia
+3  A: 

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.

Darin Dimitrov
+1  A: 

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.

KeithS
A: 

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.

Muad'Dib