这个问题之所以存在,是因为它确实存在 具有历史意义,但事实并非如此 被认为是一个很好的主题问题 因为是本网站,所以请不要使用 作为证据,你可以问类似的问题 这里的问题。 更多信息:https://stackoverflow.com/faq


总有一些功能在边缘场景中很有用,但正是因为这个原因,大多数人都不知道它们。我要求的是课本上通常没有教过的特性。

你知道的是什么?


当前回答

VS阻塞的有效语法:

<input type="checkbox" name="roles" value='<%# Eval("Name") %>' 
  <%# ((bool) Eval("InRole")) ? "checked" : "" %> 
  <%# ViewData.Model.IsInRole("Admin") ? "" : "disabled" %> />

其他回答

将位于App_Code文件夹中的类附加到全局应用程序类文件。

ASP。NET 2.0 -全球。asax -代码背后文件。

它也可以在Visual Studio 2008中工作。

你可以使用:

 Request.Params[Control.UniqueId] 

在viewstate初始化之前获取控件的值。文本等将在此时为空)。

这对于Init中的代码很有用。

这是最好的一个。把它加到你的网里。配置更快的编译。这是3.5SP1后通过这个QFE。

<compilation optimizeCompilations="true">

Quick summary: we are introducing a new optimizeCompilations switch in ASP.NET that can greatly improve the compilation speed in some scenarios. There are some catches, so read on for more details. This switch is currently available as a QFE for 3.5SP1, and will be part of VS 2010. The ASP.NET compilation system takes a very conservative approach which causes it to wipe out any previous work that it has done any time a ‘top level’ file changes. ‘Top level’ files include anything in bin and App_Code, as well as global.asax. While this works fine for small apps, it becomes nearly unusable for very large apps. E.g. a customer was running into a case where it was taking 10 minutes to refresh a page after making any change to a ‘bin’ assembly. To ease the pain, we added an ‘optimized’ compilation mode which takes a much less conservative approach to recompilation.

通过在这里:

ASHX文件类型的使用: 如果你只想输出一些基本的html或xml,而不想通过页面事件处理程序,那么你可以用一种简单的方式实现HttpModule

将页面命名为SomeHandlerPage。Ashx和只是把下面的代码(只有一行)

<%@ webhandler language="C#" class="MyNamespace.MyHandler" %>

然后是代码文件

using System;
using System.IO;
using System.Web;

namespace MyNamespace
{
    public class MyHandler: IHttpHandler
    {
        public void ProcessRequest (HttpContext context)
        {   
            context.Response.ContentType = "text/xml";
            string myString = SomeLibrary.SomeClass.SomeMethod();
            context.Response.Write(myString);
        }

        public bool IsReusable
        {
            get { return true; }
        }
    }
}

默认情况下,自定义控件的标记之间的任何内容都被添加为子控件。这可以在AddParsedSubObject()覆盖中截获,用于过滤或额外的解析(例如,LiteralControls中的文本内容):

    protected override void AddParsedSubObject(object obj)
     { var literal = obj as LiteralControl;
       if (literal != null) Controls.Add(parseControl(literal.Text));
       else base.AddParsedSubObject(obj);
     }

...

   <uc:MyControl runat='server'>
     ...this text is parsed as a LiteralControl...
  </uc:MyControl>