Understanding the runat server attribute

前端 未结 4 855
时光取名叫无心
时光取名叫无心 2020-12-03 02:13

I\'m really new to ASP.NET. I was just checking out a default ASP.NET web application. It comes by default with a few pages (Default.aspx, About.aspx etc).

I notice

4条回答
  •  旧巷少年郎
    2020-12-03 02:50

    You asked why the styles are not applied anymore when removing the runat="server" from the element.

    It is simple: by running on the server side, the parser will replace the ~/ from the stylesheet declaration with the root path of the application.

    The ~ is illegal in a URL. Thus, if this is not replaced by the parser, the file will not be found thus the stylesheet will not be applied.

    Oh, btw, setting the runat="server" attribute on the element will force all its sub-elements to be run on the server, thus why the element is run on the server.

提交回复
热议问题