BUG:设置服务器控件的InnerHtml强制调用Constructore。 [英] BUG: Setting Server Control's InnerHtml forces Constructore to be called.

查看:46
本文介绍了BUG:设置服务器控件的InnerHtml强制调用Constructore。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建购物车应用程序时,我注意到一个奇怪的错误,导致构造函数和一切被调用两次。我正在使用继承类ClassShowProducts继承了继承System.Web.UI.Page的TemplatePage,我认为这是问题所以我整天都在重新编码所有内容,以便ClassShowProducts继承自System.Web.UI.Page。然后我发现它仍然发生。

然后我迅速将其缩小到Page_Load中的一行代码(


i有一个服务器控件< td id =" tdMainContent" runat =" server">并且在我的Page_Load中我去了

tdMainContent.InnerHtml = render_MainBody(); //返回一个巨大的字符串


如果我去字符串MainContent = render_MainBody();它工作正常

然而,当我尝试设置tdMainContent.InnerHtml时,它会发出砰砰声,基本上当Page_Load结束类构造函数时会被调用并通过所有内容再次,类构造函数,OnInit,InitializeComponent,Page_Load等。


字符串的长度是4927字节,是有效的HTML内容。

做了一些tdMainBodyContent .InnerHtml = string(''c'',randomlenghs);

它看起来似乎不是内容长度相关我认为它可能与HTML结构的复杂性有关。我检查了H. TML和它是W3C有效,因为它是由XML / XSLT生成的,我知道不会有任何遗漏/打开的标签。我很茫然

While creating a shopping cart application I noticed a strange bug which resulted in the Constructor and everything being called twice. I was using Inherited classes ClassShowProducts inherited TemplatePage which inherited System.Web.UI.Page which I thought was the problem so I spent all day recoding everything so that ClassShowProducts was inherited from System.Web.UI.Page. Then I found out that it still happend.
I then quickly narrowed it down to one line of code in Page_Load(

i have a server control <td id="tdMainContent" runat="server"> and in my Page_Load i go
tdMainContent.InnerHtml = render_MainBody(); // returns a massive string

if i go string MainContent = render_MainBody(); it works fine
however the minute I try setting tdMainContent.InnerHtml it borks and basically when Page_Load ends the class constructor is called and goes through everything again, Class Constructor, OnInit, InitializeComponent, Page_Load etc.

The Length of the string is 4927 bytes and is Valid HTML Content.
After doing some tdMainBodyContent.InnerHtml = string(''c'', randomlenghs);
it does not appear to be "content length" related I am thinking it may be related to complexity of the structure of the HTML. I have checked the HTML and it is W3C Valid and since it is generated by XML/XSLT i know that there will not be any missing/open tags . I am at a loss

推荐答案




我用简单的桌子试试但是我可以'重现所描述的行为。

你能给我发送示例代码吗?

Natty Gur [MVP]


博客: http://weblogs.asp.net/ngur

手机:+ 972-(0)58-888377

***通过Developersdex发送 http://www.developersdex.com ***

不要只是参加USENET ......获得奖励!
Hi,

I try it with simple table but I can''t reproduce the described behavior.
Can you send me sample code?

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don''t just participate in USENET...get rewarded for it!


看起来它看起来问题与我有关

baseUrl.Attributes [" href"] = Constants.urlDomain

如果我在我的web项目中注释掉该行并设置了tdMainDody的InnerHtml,那么它的工作原理不会导致构造函数被抛出。然而,这在我所做的具有完全相同代码的测试项目中是不可复制的,除了它本身而不是我所在的大型项目。

----- Natty Gur写道: ----





我用简单的表尝试它但我无法重现所描述的行为

你能寄给我样例代码


Natty Gur [MVP


博客: http://weblogs.asp.net/ngu

手机:+ 972-(0)58- 88837

***通过开发人员指南 http://www.developersdex.com发送 **

不要只是参加USENET ......获得奖励

From the looks of it it appears that the problem ties into me doing
baseUrl.Attributes["href"] = Constants.urlDomain
If i comment out that line in my web project and set InnerHtml of the tdMainDody then it works without causing the constructor to be thrown. However this is not reproduceable in a test project that i made that has the exact same code except is all by itself instead of in the massive project i am in.
----- Natty Gur wrote: ----

Hi

I try it with simple table but I can''t reproduce the described behavior
Can you send me sample code

Natty Gur[MVP

blog : http://weblogs.asp.net/ngu
Mobile: +972-(0)58-88837
*** Sent via Developersdex http://www.developersdex.com **
Don''t just participate in USENET...get rewarded for it


Hello John ,


我也不能像Natty那样重复它。一般来说,如果没有重复样本,很难找到根本原因。对于这类问题的故障排除

,你可能需要使用一些调试转储来检查再次构建时调用

堆栈。无论如何,我很高兴看到你已经找到导致问题的确切行。
如果有任何我们可以为您支付的话,请随时在这里发布。


谢谢。


祝你好运,

Yanhong Huang

微软社区支持


安全! - www.microsoft.com/security

发布是按原样提供的。没有保证,也没有授予任何权利。

Hello John,

I couldn''t repro it as Natty either. Generally speaking, it is quite hard
to isolate the root cause due without a repro sample. For troubleshooting
this type of issue, you may need use some debugging dump to check call
stack when it is constructed again. Anyway, I am glad to see that you have
found the exact line which cause the problem. If there is any we can do for
you, please feel free to post here.

Thanks.

Best regards,
Yanhong Huang
Microsoft Community Support

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


这篇关于BUG:设置服务器控件的InnerHtml强制调用Constructore。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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