Page load 2 times

KaranGupta
KaranGupta used Ask the Experts™
on
Hi

I have a .net web application. I was debugging the application and I found that control goes twice on the page load. I am not sure why is it coming.

Can any one please tell me the reason and what is the solution for that.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,
There is no reason your page loads twice.

""control goes twice on the page load. I am not sure why is it coming. "" what does this mean?

Just put a breakpoint on Page_Load and see what is happening.

Author

Commented:
Hi

The reason I have written " I am not sure" is. I have already debugged that.

The situation is there are there user controls on the page. First the control goes to the parent's page load event then it goes to load event of all the three user control. I have not  found any code in javascript or in code behind where the code regarding the redirection to the same page is written.
Commented:
check in your html if you are using background property something like this
<TD valign="bottom" background="#FF1111" align="left" >

you should use bgcolor backgroud expects image url and when it finds colr code starting with # it loads same page as the background image.
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Author

Commented:
Hi

I have searched the code, but I didn't find any <td> with attribute like this

background="#FF1111"

but I found one <td> having background ="". I removed it but still I am getting the same problem,
the page is loading 2 times.

Author

Commented:
Hi

One more thing I want to share

On the page load there is a code written

Response.Expires = 0
            Response.Cache.SetNoStore()
            Response.AppendHeader("Pragma", "no-cache")

Is there something to do with page load twice.

Commented:
Is it possible to save the html and upload it here?

Commented:
>>Response.Expires = 0....
nothing to do with this.

are you using css stylesheets? if you are for testing just remove the stylesheet file and see the behaviour.

Author

Commented:
Hi appari

Still no luck even if I remove style sheet

Commented:
Is it possible to save the html and upload it here?

Author

Commented:
here we go

Please rename the file from txt to html
temp.txt
Rajkumar GsSoftware Engineer

Commented:
An event can trigger two times, when it is triggered both from code-behind (vb,c#...) and from HTML (Aspx page)

eg:- Consider a button. If OnClick="button_OnClick" is set in attribute of that button (in aspx page) & in code also it is mentioned (in VB, at the end of the click event procedure, Inherits button.OnClick), that particular event will trigger twice.

So you need to check something wrong like this.
Try these
1. Search for page_load event in code-behind & aspx page.
2. Also check this duplication in the page where this page is loading.
If this page is loading on some event of other page, check whether that particular event is duplicating like this

--Raj
To make sure I understand the problem is that you're seeing the following, correct?

1. Parent Page (.aspx) Page_Load() event fires
2. User Control 'A' (.ascx) on Parent Page (.aspx) Page_Load() event fires
3. User Control 'B' (.ascx) on Parent Page (.aspx) Page_Load() event fires
4. User Control 'C' (.ascx) on Parent Page (.aspx) Page_Load() event fires
5. Parent Page (.aspx) Page_Load() event fires
6. User Control 'A' (.ascx) on Parent Page (.aspx) Page_Load() event fires
7. User Control 'B' (.ascx) on Parent Page (.aspx) Page_Load() event fires
8. User Control 'C' (.ascx) on Parent Page (.aspx) Page_Load() event fires

If this is the case, check to see if one of the Page_Load events manipulate a control that has on *Changed or *Changing event where AutoPostBack is set to 'true'.
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

change the AutoEventWireup
AutoEventWireup =true means event fired with out having the delegate
For AutoEventWireup =false means we must have the delegates other wise those events not fired.

Example for Page_Load event:

Put the following code into comments and run with the AutoEventWireup="false" and AutoEventWireup="true.

this.Load += new System.EventHandler(this.Page_Load);


private void InitializeComponent()
{

//this.Load += new System.EventHandler(this.Page_Load);
}

private void Page_Load(object sender, System.EventArgs e)
{
if(IsPostBack==false)
{
Response.Write("hai");
}
}

Now check the results both the times.

Author

Commented:
Hi rkworlds
AutoEventWireup="false" is false

But I have no longer requires it as of now. I thank you for all your support. I am closing this question.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial