Load event behavior

M

Matt

Hello,

I just don't get it. I have a simple webform1.aspx page, when loaded
for the first time, the load even fires which is fine.

In webform1.aspx i have a button that has a onclick event, and in this
event i do a response.redirect to webform2.aspx page. However on the
onclick event of the button, the Load event for webform1.aspx is
loaded again! Then the redirection is done!

And that's not all: once we are in webform2.aspx, if i do a
response.redirect to webform1.aspx, the load event in webform1.aspx
fires twice!

Could please someone explain me this weird behavior please? Thanks
 
K

Kevin Bilbee

Matt

Matt said:
Hello,

I just don't get it. I have a simple webform1.aspx page, when loaded
for the first time, the load even fires which is fine.

In webform1.aspx i have a button that has a onclick event, and in this
event i do a response.redirect to webform2.aspx page. However on the
onclick event of the button, the Load event for webform1.aspx is
loaded again! Then the redirection is done!

And that's not all: once we are in webform2.aspx, if i do a
response.redirect to webform1.aspx, the load event in webform1.aspx
fires twice!

Could please someone explain me this weird behavior please? Thanks

Use IsPostBack in the Load event to determine if it is a post back or not.
Load will run every time the

private void Page_Load(object sender, System.EventArgs e) {
if (IsPostBack) {
// This would be run if the page is posted back like in your situation
// Do some code
} else {
// this would be executed the first time the page is loaded
// do some other code
}

Kevin Bilbee
 
D

Damian Maclennan

If you don't want the load event to fire why are you redirecting at all ?
You could just go directly to webform2 via a hyperlink or some client side
JS behind the button. That will save asp.net from having to fire up webform1
when it isn't really needed.


Damian
 
N

Natty Gur

Hi,

Could you send sample code ? I try to create this senario on machine
without any luck.

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,220
Latest member
AugustinaJ

Latest Threads

Top