由 ?ASP.Net

时间:2022-09-14 23:02:17

Is this invalid to put in an aspx file? I have some static aspx pages and I want to add a bit of C# to one of them. How can I do this?

放入aspx文件无效吗?我有一些静态的aspx页面,我想在其中添加一些c#。我该怎么做呢?

I figured just adding

我想只是添加

<%@ Page Language="c#"%>

and then using <% %> to put a bit of C# goodness in there, but it says Syntax Error. with a blue wavy line over this code.

然后使用<% %>在其中添加一点c#的优点,但是它表示语法错误。在这段代码上有一条蓝色的波浪线。

2 个解决方案

#1


28  

This happens whenever you change the Language attribute of the Page directive. Simply close the file in Visual Studio, and reopen it. The error will go away.

当您更改Page指令的语言属性时,就会发生这种情况。只需关闭Visual Studio中的文件,然后重新打开它。错误将会消失。

#2


1  

It's not entirely clear from your question, but are you adding multiple Page directives? You can only have one per .aspx file.

你的问题并不完全清楚,但是你是否添加了多个页面指令?只能有一个。aspx文件。

Otherwise what you've got there is valid. If your page works fine and VS is still showing it as an error, quit out of VS entirely and restart it.

否则你得到的是有效的。如果你的页面运行良好,VS仍然显示为一个错误,退出VS并重新启动它。

#1


28  

This happens whenever you change the Language attribute of the Page directive. Simply close the file in Visual Studio, and reopen it. The error will go away.

当您更改Page指令的语言属性时,就会发生这种情况。只需关闭Visual Studio中的文件,然后重新打开它。错误将会消失。

#2


1  

It's not entirely clear from your question, but are you adding multiple Page directives? You can only have one per .aspx file.

你的问题并不完全清楚,但是你是否添加了多个页面指令?只能有一个。aspx文件。

Otherwise what you've got there is valid. If your page works fine and VS is still showing it as an error, quit out of VS entirely and restart it.

否则你得到的是有效的。如果你的页面运行良好,VS仍然显示为一个错误,退出VS并重新启动它。