Silviu
Silviu

Reputation: 43

Why can't have control with ID "Server"

I had this line in my page:

<asp:TextBox runat="server" ID="Server" />

And I was getting the following error:

Compiler Error Message: CS1061: 'System.Web.UI.WebControls.TextBox' does not contain a definition for 'ScriptTimeout' and no extension method 'ScriptTimeout' accepting a first argument of type 'System.Web.UI.WebControls.TextBox' could be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 172:                global::ASP.applications_returndata_releasemanagement_aspx.@__initialized = true;
Line 173:            }
Line 174:            this.Server.ScriptTimeout = 30000000;
Line 175:        }
Line 176:

After changing the ID to something else it was fine.

Does anyone know why you can't use "Server" as control ID? I searched and I couldn't find anything about reserved words for asp.net controls.

Upvotes: 4

Views: 273

Answers (2)

Adrian Wragg
Adrian Wragg

Reputation: 7401

Server is one of a number of predefined properties in the base class of any ASP.Net page - this list also includes Response, Request, etc.

By calling your own control Server, you are overriding the default properties and rendering meaningless certain .Net calls including, in this case, Server.ScriptTimeout.

Upvotes: 5

Gerco Brandwijk
Gerco Brandwijk

Reputation: 150

That's because System.Web.UI.Page has already a field called Server (You can see it when you navigate to the class definition of System.Web.UI.Page).

Upvotes: 5

Related Questions