问题
I'm using ASP.NET 2.0 under VS 2005.
Page_Load
is getting called twice for my .aspx
pages. AutoEventWireup
is set to true
, but even if I set it to false and manually add the EventHandler
, it still gets fired twice.
// also set AutoEventWireup to false
public _Default() {
this.Load += new EventHander(this.Page_Load);
}
// oops -- fired twice
In the Default.aspx
page, after the user enters their username & password, I do a redirect to another page, but it seems to redirect back to the Default.aspx
page.
I don't have any <img>
tags without a src
. The tags that have a RunAt="server"
attribute are <asp:PlaceHolder>
.
For everything else, I use YUI CSS and JavaScript. I don't have any <ASP:>
controls.
What am I missing?
Update
I'm using the Button widget from the YUI library. If you specify "submit" in both Javascript and in the HTML code for a button, then when you submit, that JavaScript event gets generated twice.
This was a pain to figure out: I started commenting out bits and pieces of JavaScript and CSS (especially the includes), until the event fired only once.
回答1:
A redirect is a postback in ASP.NET. If you trigger an event(enter user name and click, 1 postback), redirect to the same page(2nd postback). Am I understanding you correctly?
回答2:
Are you by any chance using this.PreviousPage in the redirected Page ?
回答3:
So I'm using the YUI framework. And I'm using the Button widget. If you specify "submit" in both Javascript and in the HTML code for a button, then when you submit, that Javascript event gets generated twice. Just remove one of the submits.
This was a pain to figure out: just start commenting out bits and pieces of Javascript and CSS (especially the includes), until the event fires only once. That way you can see what is causing the Page_Load to get fired twice.
来源:https://stackoverflow.com/questions/1489980/yui-button-initiates-postback-twice