page load User Control

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a user control which I have registered in a webform.

In page_load method of user control, I am doing a response.write of some simple text.

I donot have any codebehind file for my webform. But when I load the WebForm in my browser, I see the text from response.write written out to the browser not once but twice!!!

Can anyone tell me why that happens? How I can avoid it? Quick response is appreciated.

Thanks,
AK
 
AK said:
Hi,

I have a user control which I have registered in a webform.

In page_load method of user control, I am doing a response.write of some simple text.

I donot have any codebehind file for my webform. But when I load the
WebForm in my browser, I see the text from response.write written out to the
browser not once but twice!!!
Can anyone tell me why that happens? How I can avoid it? Quick response is
appreciated.

One reason for Page_Load to fire twice is if you have AutoEventWireUp set to
True in the Control directive at the top of the .ascx file and at the same
time either use AddHandler to add a Load event handler for the control or if
you override the OnLoad method.

If neither of these situations apply, then I suggest that you create a
simplified reproducer for this problem. Just create a new, blank web page,
display it in Design view and then drag your user control onto the page. Run
the resulting page and see if you get the Response.Write text twice.

Also, just out of paranoia, I'd change the text of the Response.Write to
something unique, like the date followed by the time (e.g., 200407311101).
You don't say what you output in the Response.Write, so I don't know if it's
possible that you used the same text in two places. But if you use something
unique, there is no chance that it will be physically duplicated, and any
duplicate output will have to come from multiple executions of Page_Load.
 
Back
Top