Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用呈现方法重载替换复合控件中的用户控件-圆环缓存_C#_Asp.net_Substitution - Fatal编程技术网

C# 使用呈现方法重载替换复合控件中的用户控件-圆环缓存

C# 使用呈现方法重载替换复合控件中的用户控件-圆环缓存,c#,asp.net,substitution,C#,Asp.net,Substitution,我有一系列复合用户控件,它们继承自基类,基类重写控件的呈现方法。我在其中一个复合控件上放置了替换控件;但是,替换内容将写入输出流的顶部,而不是定义替换控件的位置。下面是我的渲染方法 本质上,我的目标是在覆盖用户控件上的Render方法时进行甜甜圈缓存 尽管调用了基本渲染方法,但您是否有想过为什么会发生这种情况 protected override void Render(System.Web.UI.HtmlTextWriter writer) { System.IO.StringWrit

我有一系列复合用户控件,它们继承自基类,基类重写控件的呈现方法。我在其中一个复合控件上放置了替换控件;但是,替换内容将写入输出流的顶部,而不是定义替换控件的位置。下面是我的渲染方法

本质上,我的目标是在覆盖用户控件上的Render方法时进行甜甜圈缓存

尽管调用了基本渲染方法,但您是否有想过为什么会发生这种情况

protected override void Render(System.Web.UI.HtmlTextWriter writer) {
    System.IO.StringWriter sw = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter(sw);
    base.Render(htw);
    string output = sw.ToString();
    try {
        MyPage objPage = (MyPage)this.Page;
        CustDictionary d = new CustDictionary(objPage);
        output = d.Replace(output);
    }
    catch {
        // do nothing
    }
    writer.Write(output);
}

通过对谷歌的回顾和我所做的大量测试,这在asp.NET3.5中似乎是不可能的。目标是使用替换控件或从类似控件继承来获得一个未缓存的控件。有一些方法可以利用继承和其他自定义控件来实现这一点,但是需要在控件中实例化页面以手动呈现控件,这将给应用程序带来不必要的压力。最终的解决方案是使用jQuery打印出cookie中已经存在的数据