我正在重构一堆 ASP.NET 页面。我想编译和测试我已经完成的那些。但是,Visual Studio 不允许我在非重构页面上运行出现编译错误的网站。如何在不将它们从项目本身中删除的情况下暂时排除它们?你可以通过某种配置来做到这一点吗?
我是 ASP.NET 开发的新手,我对 ASP.NET 代码隐藏机制有点好奇。
我知道我们为什么使用它,
但我想知道的是:
我的意思是在幕后发生了什么?
谢谢
这是我的 Default.aspx 页面(删除了不必要的细节):
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div id="login">
<!-- a bunch of markup has been removed, so this html will appear wrong and not valid, but it actually is -->
<table align="center" width="80%" cellpadding="0" cellspacing="0" class="loginBg">
<tr>
<td colspan="2"><img src="images/Login_top.jpg" /></td>
</tr>
<asp:Panel runat="server" ID="pnlLoginIn">
<tr>
<td style="padding-left:20px;">Username</td>
<td style="padding-right:15px;" align="right"><asp:TextBox id="txtUsername" runat="server" /></td>
<asp:RequiredFieldValidator runat="server" ID="rfvUserName" ErrorMessage="*" ControlToValidate="txtUsername" ValidationGroup="credentials" Display="Dynamic" />
</tr>
<tr>
<td style="padding-left:20px;">Password</td>
<td style="padding-right:15px;" align="right"><asp:TextBox ID="txtPassword" TextMode="Password" runat="server" /></td>
<asp:RequiredFieldValidator runat="server" ID="rfvPassword" ErrorMessage="*" ControlToValidate="txtPassword" ValidationGroup="credentials" …Run Code Online (Sandbox Code Playgroud) 我是C#.Net的新手,我有一个问题,我无法在互联网上找到.我何时应该使用html + javascript + css的经典组合,而不是使用带有代码的aspx页面?正如我从.net开始经历的那样,我发现aspx页面和代码背后对开发人员来说非常容易.自从我开始以来,我不需要任何javascript代码.一定有什么不对劲.我想我错过了一点.你能否回答我的问题并告诉我一些例子,我必须使用html + javascript + css而不是aspx + aspx.cs,反之亦然?祝你今天愉快.
在我的aspx页面中我有这个div ..
<div id="downloadableProducts" runat="server"><a href="#">Downloadedable Products</a></div>
我试图改变后面的代码中的CSS像这样..
downloadableProducts.Style("display") = "none";
但这不起作用,我downloadableProducts在后面的代码中得到一个错误和红色下划线,它说'名称'downloadableProducts'在当前上下文中不存在'
我究竟做错了什么?
我们需要在代码中确定在给定特定数据类型和该元素的情况下,哪个模板将自动应用于绑定元素。
我们并不是在寻找 DataTemplateSelector,因为它用于根据自定义逻辑告诉UI 对于给定对象使用哪个模板。相反,我们询问UI对于给定的数据类型和 UI 元素将使用哪个模板。
换句话说,我们正在寻找基于窗口资源部分中定义的模板应用的任何 WPF,这些模板可以被该窗口上的控件的资源覆盖,可以通过显式设置 DataTemplate 或直接在该元素上提供 DataTemplateSelector。
另外,我们尝试了 SelectTemplate 的默认实现,但它返回 null,所以我们也不能走这条路。
测试将询问 UI 中任何位置没有定义数据模板或选择器的元素“您将如何显示该值?” 希望它会返回一个包含 TextBlock 定义的 DataTemplate,其中文本属性设置为该对象上的 ToString 方法,这是在未定义任何其他内容时默认显示的内容。
当我尝试向母版页中的 html 标记添加属性时:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="primtag" runat="server">
Run Code Online (Sandbox Code Playgroud)
就像后面的代码一样:
prmimaryhtml_tag.Attributes.Add("lang", "en")
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: The base class includes the field 'primtag', but its type (System.Web.UI.HtmlControls.HtmlElement) is not compatible with the type of control (System.Web.UI.HtmlControls.HtmlGenericControl).
Source Error:
Line 4:
Line 5: <!DOCTYPE …Run Code Online (Sandbox Code Playgroud) 我正在尝试TapGestureRecognizer在代码上设置绑定,但我无法找到正确的方法。工作的 xaml 看起来像这样......
<Grid>
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding LaunchLocationDetailsCommand}"
CommandParameter="{Binding}" />
</Grid.GestureRecognizers>
</Grid>
Run Code Online (Sandbox Code Playgroud)
在 C# 中,它看起来像这样......
var gridTap = new TapGestureRecognizer();
gridTap.SetBinding(TapGestureRecognizer.CommandProperty,
new Binding("LaunchLocationDetailsCommand"));
gridTap.SetBinding(TapGestureRecognizer.CommandParameterProperty,
new Binding(/* here's where I'm confused */));
var grid = new Grid();
grid.GestureRecognizers.Add(gridTap);
Run Code Online (Sandbox Code Playgroud)
我的困惑来自CommandParameterProperty. 在 xaml 中,这只是{Binding}没有其他参数。这是如何在代码中完成的?传入new Binding()或this.BindingContext似乎不起作用。
我需要从代码隐藏访问列表视图的滚动查看器。这是我的列表视图的定义
<ListView Grid.Row="1" ItemsSource="{Binding Path=SpecList, UpdateSourceTrigger=PropertyChanged}"
Name="mylistview"
ItemTemplate="{StaticResource SpecElementTemplate}"
Background="{StaticResource EnvLayout}"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ItemContainerStyle="{StaticResource MyStyle}"
BorderBrush="Blue"
BorderThickness="20"
Margin="-2">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得滚动查看器?
谢谢
安德烈亚
当我在Visual Studio 2017中创建新的 Razor 页面时,未创建分离的代码隐藏文件。
这是突出显示的问题的屏幕截图。

我们可以看到调用的 Razor 页面List.cshtml不包含代码隐藏文件。about.cshtml例如,将其与默认页面进行对比。
code-behind ×10
asp.net ×7
c# ×6
html ×2
wpf ×2
.net ×1
css ×1
datatemplate ×1
javascript ×1
listview ×1
razor ×1
razor-pages ×1
scrollviewer ×1
vb.net ×1
webforms ×1
xamarin ×1