And I got the...">

Why there can be no control with the identifier "Server"

I had this line on my page:

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

And I got the following error:

Compiler error message: CS1061: "System.Web.UI.WebControls.TextBox" does not contain a definition for "ScriptTimeout" and no extension method "ScriptTimeout" that takes the first argument of the type "System.Web.UI.WebControls.TextBox '(you lacking a using directive or assembly references?)

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 identifier to something else, that was good.

Does anyone know why you cannot use Server as an identifier for a control? I searched and I could not find anything about reserved words for asp.net controls.

+4
source share
2 answers

This is because System.Web.UI.Page already has a field called Server (you can see it when you go to the definition of the System.Web.UI.Page class).

+5
source

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

By invoking your own Server control, you override the default properties and provide meaningless defined .Net calls, including in this case Server.ScriptTimeout .

+5
source

Source: https://habr.com/ru/post/1499330/


All Articles