LoadControl(virtualPath)是否在单个请求中缓存控件。如果是这样,我可以禁用它。 [英] Is LoadControl (virtualPath) is caching controls in a single request. If so, can i disable it.

查看:86
本文介绍了LoadControl(virtualPath)是否在单个请求中缓存控件。如果是这样,我可以禁用它。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来,它正在缓存它。

以下代码就是一个例子。如何避免这种情况。


覆盖void OnLoad(发送者和eventargs)

{

控制控制= this.LoadControl(路径);

this.Controls.Add(control);


//我改变了控件的html内容。

TextReader reader = new StreamReader(path);

string content = reader.ReadToEnd();

reader.Close();

TextWriter writer = new StreamWriter(path);

writer.Write(content +"< b> NewPart< / b>");

writer.Close ();

}


覆盖void OnPreRender(发件人和eventargs)

{

/ / Altough我已经改变了控件的内容,仍然加载了相同的控件



控制控件= this.LoadControl(路径);

this.Controls.Add(control);

}


我没有从VS复制粘贴此代码。可能会有一些实施

的错误。对不起。

It seems, it is caching it.
The following code is an example for it. How can avoid from this.

override void OnLoad (sender and eventargs)
{
Control control = this.LoadControl (path);
this.Controls.Add (control);

// I change the content of the html of the control.
TextReader reader = new StreamReader (path);
string content = reader.ReadToEnd ();
reader.Close();
TextWriter writer = new StreamWriter (path);
writer.Write (content + "<b>NewPart</b>");
writer.Close ();
}

override void OnPreRender (sender and eventargs)
{
// Altough i have changed the content of the control, still same control
is loaded.
Control control = this.LoadControl (path);
this.Controls.Add (control);
}

I have not copy-paste this code from VS. There may be some implementation
mistakes. Sorry for this.

推荐答案

您好Umut,


感谢您的发布。对于你提到的LoadControl的缓存问题,我已经对Page.LoadControl

方法做了一些深入研究。实际上,它调用了TemplateControl.LoadControl方法,并且
将从临时文件夹中查找控件的类型。所以,当你再次调用LoadControl时(在同一页面的请求生命周期中),它将会从临时文件夹中检索缓存的项目,而不是解析

原始ascx文件,这主要是出于性能考虑。

另外,因为这个缓存只适用于在

期间加载相同的UserControl同一页面请求处理,所以如果我们再次刷新或回发页面

,该页面将从其

实际位置加载更新的控件(ascx文件)。


如果您还有其他不清楚的地方,请随时在此处发布。谢谢。


问候,


Steven Cheng

微软在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)

Hi Umut,

Thanks for posting. AS for the LoadControl''s caching problem you
mentioned, I''ve done some deep investigate into the Page.LoadControl
method. In fact, it is calling the TemplateControl.LoadControl method and
will looking for the control''s type from a temporary folder. So when you
call the LoadControl again(during the same page request lifecycle), it''ll
retrieve the cached item from the temporary folder rather than parsing the
raw ascx file again, this is mainly for performance consideration.
Also, since this caching only work for loading the same UserControl during
the same page request processing, so if we refresh or post back the page
again, the page will loaded the updated control (ascx file ) from its
actual position.

If you have anything else unclear , please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


有没有办法禁用此功能。我想在页面中加载一个控件两次

请求。在按钮的单击事件中,其内容已更改。我有

来做Response.Redirect()。但这是浪费时间。


Steven Cheng [MSFT]" <,V - ****** @ online.microsoft.com>在消息中写道

news:ap ************** @ cpmsftngxa10.phx.gbl ...
Is there a way to disable this. I want to load a control twice in a page
request. And in the click event of a button, its content was changed. I have
to do Response.Redirect (). But it is waste of time.

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:ap**************@cpmsftngxa10.phx.gbl...
嗨Umut,

感谢发帖。对于你提到的LoadControl的缓存问题,我已经对Page.LoadControl
方法做了一些深入研究。实际上,它调用TemplateControl.LoadControl方法并且将从临时文件夹中查找控件的类型。因此,当您再次调用LoadControl时(在同一页面请求生命周期中),它将从临时文件夹中检索缓存的项目,而不是再次解析
原始ascx文件,这主要是出于性能考虑。
此外,由于此缓存仅适用于在同一页面请求处理期间加载相同的UserControl,因此如果我们再次刷新或回发页面
,页面将从其实际位置加载更新的控件(ascx文件)。

如果您还有其他不清楚的地方,请随时在此处发布。谢谢。

问候,

Steven Cheng
微软在线支持

获得安全! www.microsoft.com/security
(此帖已提供按原样,没有保证,也没有赋予
权利。)
Hi Umut,

Thanks for posting. AS for the LoadControl''s caching problem you
mentioned, I''ve done some deep investigate into the Page.LoadControl
method. In fact, it is calling the TemplateControl.LoadControl method and
will looking for the control''s type from a temporary folder. So when you
call the LoadControl again(during the same page request lifecycle), it''ll
retrieve the cached item from the temporary folder rather than parsing the
raw ascx file again, this is mainly for performance consideration.
Also, since this caching only work for loading the same UserControl during
the same page request processing, so if we refresh or post back the page
again, the page will loaded the updated control (ascx file ) from its
actual position.

If you have anything else unclear , please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)



嗨Umut,


感谢您的回复。正如我在你的另一个帖子中提到的那样,这个群体是
。经常修改aspx或ascx源文件会使

asp.net经常重新编译asp.net运行时生成的程序集,这可能会产生性能问题。此外,当重新编​​译时间超过

asp.net的配置设置时,它将重新启动Web应用程序,我

不要以为''你想看什么。目前我的建议是尝试

将UserControl的UI更改代码放入Control的代码隐藏中。

例如:


我们定义一个具有状态的UserControl。属性。然后在

UserControl的Load事件中,我们可以根据状态修改UserControl的UI部分。当我们通过Page.LoadControl在页面中加载它时,可以分配

的属性。你怎么想这个怎么样?


谢谢。


问候,

Steven Cheng

微软在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)

Hi Umut,

Thanks for your response. As I''ve also mentioned in your another thread in
this group. Frequently modifying the aspx or ascx source file will make the
asp.net frequently recompile the asp.net runtime generated assembly which
may have performance concerns. Also, when the recompile time exceed the
asp.net''s configuration setting, it will restart the web application, I
don''t think that''s what you want to see. And currently my suggestion is try
putting the UserControl''s UI changing code into the Control''s codebehind.
For example:

We define a UserControl which has a "Status" property. Then in the
UserControl''s Load event, we can

modify the UserControl''s UI Part according to the "Status" Property which
can be assigned when we Load it in the page via Page.LoadControl. How do
you think of this?

Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


这篇关于LoadControl(virtualPath)是否在单个请求中缓存控件。如果是这样,我可以禁用它。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆