473,388 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

BUG: Setting Server Control's InnerHtml forces Constructore to be called.

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
Nov 18 '05 #1
10 1756
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!
Nov 18 '05 #2
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

Nov 18 '05 #3
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.

Nov 18 '05 #4
Actually I did not find the root problem. Well I sort of did.
I more found a way to reproduce it every single tim
I have rebuilt over 7 different projects and recoded another one racking my brain trying to figure it out but at least I think i can now reproduce it as i've created 2 new projects and gotten it to exhibit this behavior. I will be posting a sample in just a second.

It seems to be tied to the fact that I have a class named _Default because one of my webpages is Default.asp
For example i did thi

Created a New Web Project -> Copied the Sample code. added a constructor and set a breakpoint on the constructor
Ran the project and it only got called once
So i went (because i already knew this was reproduceable) and added a new page called Default.aspx and set it as the Startup Page. I added the same code and created a constructor and set a breakpoint. Running the project prove that the constructor got called a second time.

Now because my last project was using an Inherited Page Structure this was happening on every single page. So i tested something by setting WebForm1.aspx as the startup page and ran it with breakpoints on both constructors
Webform1.aspx got called and a breakpoint happned in Webform1's Constructor. i hit f5 and then the the next breakpoint popped on Default's Constructor even though Webform1.aspx page was the Startup page.

Is there something I am missing that is special about "Default.aspx" ?
Nov 18 '05 #5
What seems to be even funnier is that after one has added a Web Form via Project -> Add New Item -> Webform -> Default.aspx -> and then renamed it appears that this still happens.

I will post sample files under a different ID as I can't attach emails via the web interface
----- jo*****@driver.net wrote: ----

Actually I did not find the root problem. Well I sort of did.
I more found a way to reproduce it every single tim
I have rebuilt over 7 different projects and recoded another one racking my brain trying to figure it out but at least I think i can now reproduce it as i've created 2 new projects and gotten it to exhibit this behavior. I will be posting a sample in just a second.

It seems to be tied to the fact that I have a class named _Default because one of my webpages is Default.asp
For example i did thi

Created a New Web Project -> Copied the Sample code. added a constructor and set a breakpoint on the constructor
Ran the project and it only got called once
So i went (because i already knew this was reproduceable) and added a new page called Default.aspx and set it as the Startup Page. I added the same code and created a constructor and set a breakpoint. Running the project prove that the constructor got called a second time.

Now because my last project was using an Inherited Page Structure this was happening on every single page. So i tested something by setting WebForm1.aspx as the startup page and ran it with breakpoints on both constructors
Webform1.aspx got called and a breakpoint happned in Webform1's Constructor. i hit f5 and then the the next breakpoint popped on Default's Constructor even though Webform1.aspx page was the Startup page.
Is there something I am missing that is special about "Default.aspx" ?
Nov 18 '05 #6
Hi,
Thanks for your responses and the sample project you've attached. I've
tested on our application and here is the result I've got:
#I've added break point in all the page classes' constructor(default,
WebForm1 and WebForm2) and set them as startup page separatly. However, I
found that each page's aspx has the below code
<body onload="bodyOnLoad();">
but the "bodyOnLoad()" client script functdion is not found in aspx page so
that everytime after the page's constructor(first time), the will throw a
"no Object Reference error" which indicate that the BodyOnLoad function not
defined. Would you please provide the "bodyOnLoad()" function so that I can
contintue the test?

In addition, if I remove the onload="bodyOnLoad();" block, each page is ok
to run under F5 debug , but each time their construct will be called only
once rather than second time. So I also doubt whether the problem is due to
the "bodyOnLoad()" function ?

Please check out the above things. If you have any new findings, please
feel free to post here.
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.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #7
the onload="Onload..." has nothing to do with that. That was client side javascript left over from the project that got messed up. According to my discovers as stated before it appears that naming a class _default is causing the constructor to be called twice.
In the attached project or by going
File -> New Web Project ->
Switch to HTML view and copy the HTML code provided in my project - remove the onload so you do not get JS errors.
Switch back to Design view and double click and then copy the code i provided in the Page_Loa
set a breakpoint here or create a constructor and put a breakpoint in there.

Then Project -> Add New Page -> Default.aspx
Repeate the above steps and then set it up as the Start page
On every single new project that I created the minute I did this whenever i ran the project the constructor was called twice.

And as I described before renaming the class to something normal does not rectify the problem. I had to manually close the project and create a new one in order to get it working.

(I can't believe it is not reproduceable as i've been able to do it every single time once i figured it out exactly what was causing the problem) namely having a web form called Default.aspx which would create a class called _Default
Nov 18 '05 #8
Weee. 5th project wasted. 3rd day wasted. I am not sure how this is not coming up as reproduceable as i've laid waste to many hours rebuilding projects only to have it show back up. I think this time it showed up by me just renaming Webform1.aspx to a Default.aspx while leaving the class name the same. Going to spend a few more hours destroying and rebuilding from scratch again
Nov 18 '05 #9
Hi,
I'm viewing the issue and found that this is the same one with another
thread subjected:
BUG: Setting Server Control's InnerHtml forces Constructore to be called.
I've repro your problem and found the root cause of the issue. Also, I've
posted my reply in that one. Please check out it and feel free to post
there if you have any questions on it. 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.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #10
Okay. That sound's reasonable. So hopefuly if it comes back i should just
look for an <img tag without any empty src specified. I wish i would have
seent he pattern before. Thanks for everything

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:UM****************@cpmsftngxa06.phx.gbl...
Hi,
Thanks for your followup. I've done some further tests on different
machines and finally found out the root cause of this issue. The problem
is
caused by the "Default Documents" set in the VirtualDirctory, the by
default an IIS Virtual Directory's Default Documents are "default.htm",
"index.htm", "default.asp", "iisstart.asp". And maybe has the
"default.aspx" . The "Default Documents" means when you didn't specify a
certain file name in a url , such as
"http://localhost/WebApplication5/" then, the IIS will search in the
default documents, if any one find then redirect to that certain file. And
also if you used some certain relative path url to refer a no file
specified url such as
<img src=""/> (if this image tag is in a page in the virutal directory's
root folder) then, the default document will also be called.

And from your code in the string you set in the page_load
private void Page_Load(object sender, System.EventArgs e)
{
tdMainBodyContent.InnerHtml = "......."
}
There contains an "<img src=\"\">", yes? You may have a check, then, that
cause the IIS search for the default documents and you can check the
WebApplication5's virual directory's Default Document attributes to see
whether the "Default.aspx" is in the list, I'm sure it is in that list ,
and that's why the Default.aspx is caused again. So this problem can be
repro event if we hard code a <img src=""> tag in the aspx page. And I've
add one of my repro page named "MyReproPage" in the modified project I've
attached in this message. Please check it out.

In addition, as for my last reply( I mentioned that I didn't repro this
problem). That's because I firstly test in a machine(WINXP) on which the
IIS by default didn't add the "Default.aspx" into the default documents.
However, when I tried testing on a WIN2003 server machine,where by default
"Default.aspx" is added in the virual directory's default documents, then
I
was managed to repro this. Seems a bit lucky:).

Anyway, please check out the above results. If you found any difference
from my result or have any further questions, please feel free to post
here.


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.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jim Mitchell | last post by:
I have a web page that I show using show ModalDialog. The web page takes about 6 seconds to load. No matter what I try, I can not get the cursor to show a "WAIT" until the page is loaded in...
4
by: Howard Jess | last post by:
In Opera 8.01 (Linux; Build 1204) and in Opera 7.54 (Windows XP; Build 3865), my form disappears from the HTML markup (below). To summarize: 1) In a <script> block in the <head> I create a form...
9
by: Just D. | last post by:
All, Did anybody see this strange effect? The web application is written in C#, ASP.NET, SQL, T-SQL, etc. A pretty usual stuff, complicated enough, but works fine until... Here is a question....
3
by: Diego F. | last post by:
Hello. I'm trying to call a function that prints the content of a div element. I had that javascript code working, but now I must put that code in the server side, as it is called from another...
5
by: Dave A | last post by:
I am writing an ASP.NET tool that will allow the client to create their own online froms. ie the client can add tect boxes, text, drop downs,etc with absolutely no technical skill what so ever....
3
by: Jon Delano | last post by:
Hi I was wondering if it were possible to somehow stop a page from posting back to the server and running the server side code. I have a datagrid and the first column is basically a button. I...
6
by: den 2005 | last post by:
Hi everybody, Question 1: How do you set the values from server-side to a client-side control or how do you execute a javascript function without a button click event? Question 2: How do you...
20
by: tshad | last post by:
I had posted this problem earlier and just noticed that the Hyperlink is the problem. Apparently, it doesn't figure out the path correctly. It uses the path of the file it is in, even if it is...
12
by: Juan T. Llibre | last post by:
re: !I found an MSDN document that explains why what I'm trying to do should work Lee, From : http://www.w3.org/TR/REC-xml/ "A special attribute named xml:lang may be inserted in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.