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


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

你知道的是什么?


当前回答

在网站发布并部署到生产服务器后,如果我们需要对服务器端按钮进行一些更改,则单击事件。我们可以在aspx页面本身中使用new关键字来覆盖现有的click事件。

例子

代码背后方法

 Protected void button_click(sender object, e System.EventArgs) 
  {
     Response.Write("Look Ma', I Am code behind code!")  
  }

覆盖方法:

<script runat="server">   
   Protected void new button_click(sender object, e System.EventArgs) 
  {
     Response.Write("Look Ma', I am overrided method!")  
  }

</script

通过这种方式,我们可以轻松地修复生产服务器错误,而无需重新部署。

其他回答

当我将xmlDocument()转储到标签中并使用它的xsl转换显示时,我认为这很整洁。

基于目标浏览器设置服务器控件属性等。

<asp:Label runat="server" ID="labelText" ie:Text="这是ie文本" mozilla:Text="这是Firefox文本" 文本="这是一般文本" />

这句话让我有点吃惊。

你可以使用UniqueID属性找到任何控件:

Label label = (Label)Page.FindControl("UserControl1$Label1");

System.Web.Hosting.HostingEnvironment.MapPath

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; }
        }
    }
}