标签: code-behind

如何从编译中排除 ASP.NET 网站代码隐藏文件?

我正在重构一堆 ASP.NET 页面。我想编译和测试我已经完成的那些。但是,Visual Studio 不允许我在非重构页面上运行出现编译错误的网站。如何在不将它们从项目本身中删除的情况下暂时排除它们?你可以通过某种配置来做到这一点吗?

asp.net code-behind visual-studio

5
推荐指数
1
解决办法
3148
查看次数

背后的asp.net 代码是如何工作的?

我是 ASP.NET 开发的新手,我对 ASP.NET 代码隐藏机制有点好奇。
我知道我们为什么使用它,
但我想知道的是:

  • aspx页面与背后代码的关系
  • 谁负责这两个独立文件之间的链接?
  • 它是如何工作的?
  • 如何从后面的代码直接访问在 aspx 页面中创建的元素?

    我的意思是在幕后发生了什么?

    谢谢

  • asp.net code-behind visual-studio

    5
    推荐指数
    0
    解决办法
    2494
    查看次数

    代码隐藏页面无法“看到”在 aspx 页面中声明的任何项目/控件

    这是我的 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)

    .net c# asp.net compiler-errors code-behind

    5
    推荐指数
    1
    解决办法
    1万
    查看次数

    何时使用javascript而不是创建aspx页面?

    我是C#.Net的新手,我有一个问题,我无法在互联网上找到.我何时应该使用html + javascript + css的经典组合,而不是使用带有代码的aspx页面?正如我从.net开始经历的那样,我发现aspx页面和代码背后对开发人员来说非常容易.自从我开始以来,我不需要任何javascript代码.一定有什么不对劲.我想我错过了一点.你能否回答我的问题并告诉我一些例子,我必须使用html + javascript + css而不是aspx + aspx.cs,反之亦然?祝你今天愉快.

    html javascript c# asp.net code-behind

    5
    推荐指数
    2
    解决办法
    2116
    查看次数

    在asp.net后面的代码中更改CSS

    在我的aspx页面中我有这个div ..

    <div id="downloadableProducts" runat="server"><a href="#">Downloadedable Products</a></div>

    我试图改变后面的代码中的CSS像这样..

    downloadableProducts.Style("display") = "none";

    但这不起作用,我downloadableProducts在后面的代码中得到一个错误和红色下划线,它说'名称'downloadableProducts'在当前上下文中不存在'

    我究竟做错了什么?

    css c# asp.net code-behind

    5
    推荐指数
    1
    解决办法
    8927
    查看次数

    如何以编程方式检索用于 UI 层次结构中特定元素的 DataTemplate?

    我们需要在代码中确定在给定特定数据类型和该元素的情况下,哪个模板将自动应用于绑定元素。

    我们并不是在寻找 DataTemplateSelector,因为它用于根据自定义逻辑告诉UI 对于给定对象使用哪个模板。相反,我们询问UI对于给定的数据类型和 UI 元素将使用哪个模板。

    换句话说,我们正在寻找基于窗口资源部分中定义的模板应用的任何 WPF,这些模板可以被该窗口上的控件的资源覆盖,可以通过显式设置 DataTemplate 或直接在该元素上提供 DataTemplateSelector。

    另外,我们尝试了 SelectTemplate 的默认实现,但它返回 null,所以我们也不能走这条路。

    测试将询问 UI 中任何位置没有定义数据模板或选择器的元素“您将如何显示该值?” 希望它会返回一个包含 TextBlock 定义的 DataTemplate,其中文本属性设置为该对象上的 ToString 方法,这是在未定义任何其他内容时默认显示的内容。

    c# wpf code-behind datatemplate

    5
    推荐指数
    1
    解决办法
    1056
    查看次数

    通过代码隐藏结果​​向 html 标记添加属性会导致错误类型 (System.Web.UI.HtmlControls.HtmlElement) 不兼容

    当我尝试向母版页中的 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)

    html vb.net asp.net webforms code-behind

    5
    推荐指数
    1
    解决办法
    3952
    查看次数

    在后面的代码中设置 Xamarin.Forms 绑定 CommandParameter

    我正在尝试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似乎不起作用。

    c# code-behind xamarin xamarin.forms

    5
    推荐指数
    1
    解决办法
    2万
    查看次数

    WPF访问列表视图代码隐藏的滚动查看器

    我需要从代码隐藏访问列表视图的滚动查看器。这是我的列表视图的定义

    <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)

    我怎样才能获得滚动查看器?

    谢谢

    安德烈亚

    c# wpf listview code-behind scrollviewer

    5
    推荐指数
    1
    解决办法
    4590
    查看次数

    如何创建 Razor 页面的后台代码

    当我在Visual Studio 2017中创建新的 Razor 页面时,未创建分离的代码隐藏文件。

    这是突出显示的问题的屏幕截图。

    在此输入图像描述

    我们可以看到调用的 Razor 页面List.cshtml不包含代码隐藏文件。about.cshtml例如,将其与默认页面进行对比。

    asp.net model-view-controller code-behind razor razor-pages

    5
    推荐指数
    1
    解决办法
    1万
    查看次数