且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Page_Load被调用两次

更新时间:2023-10-31 18:34:16

您是否将AutoEventWireup设置为true

(或者您没有定义它,因为默认情况下是真的)?


当你设置AutoEventWireup时,页面事件会自动绑定到使用

Page_event的命名约定的方法,例如Page_Load to true或者不设置为false。


如果你将AutoEventWireup设置为true,然后使用Handles语句,

你会得到两次调用Page事件,一次通过AutoEventWireup,

,再次使用Handles时。


通过将AutoEventWireup设置为false或消除Handles语句进行测试。


Juan T. Llibre,asp.net MVP

asp.net faq: http://asp.net.do/faq/

foros de asp.net,en espa?ol: http://asp.net.do/foros/

=== ================================

< fi ******* ***@gmail.com在留言中写道

新闻:11 ********************** @ c35g2000hsg.googlegr oups.com ...

>我使用的是ASP.NET 2005,我有一个简单的表单。 Page_Load调用了一个没有做任何事情的
sub mySub(用于测试目的)。但是,

Page_Load被调用两次。

在我网站的每个ASPX页面上,Page_Load被调用两次。为什么

是那个,我该如何解决这个问题呢?

非常感谢。


Imports System.IO

命名空间myProject

部分类WebForm1

继承System.Web.UI.Page

受保护WithEvents HyperLink1 As

System.Web.UI.WebControls.HyperLink


#Region" Web表单设计器生成的代码

'Web表单设计器需要此调用。

< System.Diagnostics.DebuggerStepThrough()>

Private Sub InitializeComponent()

End Sub


Private Sub Page_Init(ByVal sender As System.Object,ByVal e

As System.EventArgs)处理MyBase.Init

''CODEGEN:Web表格需要此方法调用

设计师

' '不要使用代码编辑器修改它。

InitializeComponent()

End Sub

#End Region


Protected Sub Page_Load(ByVal sender As System.Object,ByVal e

As System.EventArgs)处理MyBase.Load,Me.Load

mySub()
结束次级

Sub mySub()

结束次级

结束班级

结束命名空间



ockquote>

感谢您的回复。

>您是否将AutoEventWireup设置为true?



我是否在myPage.aspx中找到了这个?

这就是myPage.aspx中的内容:

<%@ Page Language =" vb" AutoEventWireup =" false"
Inherits =" Auction.WebForm1"的CodeFile = QUOT; myPage.aspx.vb&QUOT; %>

我没有定义/更改它,就像那样。这是否意味着

设置为False?


通过将AutoEventWireup设置为false或消除Handles语句来进行测试。



如何消除Handles声明?


谢谢。

4月29日,7:16 pm,Juan T. Llibre, < nomailrepl ... @ nowhere.com>

写道:


你是否将AutoEventWireup设置为true

(或者你没有定义它,因为默认情况下它是真的)?

页面事件自动绑定到使用命名约定的方法

当你将AutoEventWireup设置为true或者没有将它设置为false时,Page_event,例如Page_Load。


如果将AutoEventWireup设置为true,然后使用Handles语句,

您将获得两次调用Page事件,一次使用AutoEventWireup,

并且当您使用Handles时再次调用。


通过将AutoEventWireup设置为false来测试,或者通过消除Handles声明。


Juan T. Llibre,asp.net MVP

asp.net faq: http://asp.net.do/faq/

foros de asp.net,en espa?ol: http://asp.ne t.do/foros/

================================ ===< fiefie.ni ... @g mail.comwrote in message


新闻:11 ***************** *****@c35g2000hsg.googlegr oups.com ...

我使用的是ASP.NET 2005,我有一个简单的表单。 Page_Load调用了一个没有做任何事情的
sub mySub(用于测试目的)。但是,

Page_Load被调用两次。

在我网站的每个ASPX页面上,Page_Load被调用两次。为什么

是那个,我该如何解决这个问题呢?

非常感谢你。


Imports System.IO

命名空间myProject

部分类WebForm1

继承System.Web.UI.Page

受保护WithEvents HyperLink1 As

System.Web.UI.WebControls.HyperLink


#Region" Web表单设计器生成的代码

'Web表单设计器需要此调用。

< System.Diagnostics.DebuggerStepThrough()>

Private Sub InitializeComponent()

End Sub


Private Sub Page_Init(ByVal sender As System.Object, ByVal e

As System.EventArgs)处理MyBase.Init

''CODEGEN:Web表格需要此方法调用

Designer

''不要使用代码编辑器修改它。

InitializeComponent()

End Sub

#End Region


Protected Sub Page_Load(ByVal sender As System.Object,ByVal e

As System.EventArgs)处理MyBase.Load ,Me.Load

mySub()

End Sub

Sub mySub()

结束子

结束类

结束命名空间 - 隐藏引用文本 -



- 显示引用的文字 -



re:

!这就是它在myPage.aspx中所说的内容:

!<%@ Page Language =" vb" AutoEventWireup =" false"

!这是否意味着它被设置为False?


是的,它设置为false。


re:

如何消除Handles语句?



由于你已经将AutoEventWireup设置为false,所以你所要做的就是消除代码库的双重加载

。即,你现在有这个:


受保护的子Page_Load(...)处理MyBase.Load,Me.Load


加载代码两次(一次使用MyBase.Load,另一次使用Me.Load)

在ASP.NET 1.1中你可以侥幸逃脱,但2.0更严格。


使用:

受保护的子Page_Load(ByVal发送者为System.Object,ByVal e As System.EventArgs)句柄

MyBase.Load


如果将AutoEventWireup设置为true,则不需要Handles方法,并且可以使用:


受保护的子Page_Load(ByVal sender As System.Object ,ByVal e As System.EventArgs)


Juan T. Llibre,asp.net MVP

asp.net faq: http://asp.net.do/faq/

foros de asp.net,en espa?ol: http://asp.net.do/foros /

============================== =====

< fi ********** @ gmail.comwrote in message

news:11 ******* ***************@u30g2000hsc.googlegr oups.com ...

感谢您的回复。


>您是否将AutoEventWireup设置为true?



我是否在myPage.aspx中找到了这个?

这就是myPage.aspx中的内容:

<%@ Page Language =" vb" AutoEventWireup =" false"
Inherits =" Auction.WebForm1"的CodeFile = QUOT; myPage.aspx.vb&QUOT; %>

我没有定义/更改它,就像那样。这是否意味着

设置为False?


通过将AutoEventWireup设置为false或消除Handles语句来进行测试。



如何消除Handles声明?


谢谢。

4月29日,7:16 pm,Juan T. Llibre, < nomailrepl ... @ nowhere.com>

写道:


你是否将AutoEventWireup设置为true

(或者你没有定义它,因为默认情况下它是真的)?

页面事件自动绑定到使用命名约定的方法

当你将AutoEventWireup设置为true或者没有将它设置为false时,Page_event,例如Page_Load。


如果将AutoEventWireup设置为true,然后使用Handles语句,

您将获得两次调用Page事件,一次使用AutoEventWireup,

并且当您使用Handles时再次调用。


通过将AutoEventWireup设置为false来测试,或者通过消除Handles声明。


Juan T. Llibre,asp.net MVP

asp.net faq: http://asp.net.do/faq/

foros de asp.net,en espa?ol: http://asp.ne t.do/foros/

================================ ===



< fiefie.ni ... @ gmail.comwrote in message


&gt ;

新闻:11 ********************** @ c35g2000hsg.googlegr oups.com ......

我使用的是ASP.NET 2005,我有一个简单的表单。 Page_Load调用了一个没有做任何事情的
sub mySub(用于测试目的)。但是,

Page_Load被调用两次。

在我网站的每个ASPX页面上,Page_Load被调用两次。为什么

是那个,我该如何解决这个问题呢?

非常感谢你。


Imports System.IO

命名空间myProject

部分类WebForm1

继承System.Web.UI.Page

受保护WithEvents HyperLink1 As

System.Web.UI.WebControls.HyperLink


#Region" Web表单设计器生成的代码

'Web表单设计器需要此调用。

< System.Diagnostics.DebuggerStepThrough()>

Private Sub InitializeComponent()

End Sub


Private Sub Page_Init(ByVal sender As System.Object, ByVal e

As System.EventArgs)处理MyBase.Init

''CODEGEN:Web表格需要此方法调用

Designer

''不要使用代码编辑器修改它。

InitializeComponent()

End Sub

#End Region


Protected Sub Page_Load(ByVal sender As System.Object,ByVal e

As System.EventArgs)处理MyBase.Load ,Me.Load

mySub()

End Sub

Sub mySub()

结束子

结束类

结束命名空间 - 隐藏引用文本 -



- 显示引用的文字 -




I am using ASP.NET 2005 and I have a simple form. Page_Load calls a
sub mySub that does not do anything (for testing purposes). But,
Page_Load gets called twice.
On every single ASPX page in my site, Page_Load gets called twice. Why
is that and how can I fix this problem ?
Thank you very much.

Imports System.IO
Namespace myProject
Partial Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents HyperLink1 As
System.Web.UI.WebControls.HyperLink

#Region " Web Form Designer Generated Code "
''This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Init
''CODEGEN: This method call is required by the Web Form
Designer
''Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region

Protected Sub Page_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load, Me.Load
mySub()
End Sub
Sub mySub()
End Sub
End Class
End Namespace

Are you setting AutoEventWireup to true
(or are you not defining it, since by default it is true) ?

Page events are automatically bound to methods that use the naming convention of
Page_event, such as Page_Load, when you set AutoEventWireup to true or not set it to false.

If you set AutoEventWireup to true, and then use the Handles statement,
you will get Page events called twice, once by AutoEventWireup,
and again when you use Handles.

Test by setting AutoEventWireup to false, or by eliminating the Handles statement.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
===================================
<fi**********@gmail.comwrote in message
news:11**********************@c35g2000hsg.googlegr oups.com...
>I am using ASP.NET 2005 and I have a simple form. Page_Load calls a
sub mySub that does not do anything (for testing purposes). But,
Page_Load gets called twice.
On every single ASPX page in my site, Page_Load gets called twice. Why
is that and how can I fix this problem ?
Thank you very much.

Imports System.IO
Namespace myProject
Partial Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents HyperLink1 As
System.Web.UI.WebControls.HyperLink

#Region " Web Form Designer Generated Code "
''This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Init
''CODEGEN: This method call is required by the Web Form
Designer
''Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region

Protected Sub Page_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load, Me.Load
mySub()
End Sub
Sub mySub()
End Sub
End Class
End Namespace




Thank you for your reply.
>Are you setting AutoEventWireup to true ?

Do I find this in the myPage.aspx ?
This is what it says in myPage.aspx:
<%@ Page Language="vb" AutoEventWireup="false"
Inherits="Auction.WebForm1" CodeFile="myPage.aspx.vb" %>
I do not define/change it, it is like that already. Does it mean that
it is set to False ?

Test by setting AutoEventWireup to false, or by eliminating the Handles statement.

How can I eliminate the Handles statement ?

Thank you.
On Apr 29, 7:16 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:

Are you setting AutoEventWireup to true
(or are you not defining it, since by default it is true) ?

Page events are automatically bound to methods that use the naming convention of
Page_event, such as Page_Load, when you set AutoEventWireup to true or not set it to false.

If you set AutoEventWireup to true, and then use the Handles statement,
you will get Page events called twice, once by AutoEventWireup,
and again when you use Handles.

Test by setting AutoEventWireup to false, or by eliminating the Handles statement.

Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en espa?ol :http://asp.net.do/foros/
===================================<fiefie.ni...@g mail.comwrote in message

news:11**********************@c35g2000hsg.googlegr oups.com...
I am using ASP.NET 2005 and I have a simple form. Page_Load calls a
sub mySub that does not do anything (for testing purposes). But,
Page_Load gets called twice.
On every single ASPX page in my site, Page_Load gets called twice. Why
is that and how can I fix this problem ?
Thank you very much.

Imports System.IO
Namespace myProject
Partial Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents HyperLink1 As
System.Web.UI.WebControls.HyperLink

#Region " Web Form Designer Generated Code "
''This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Init
''CODEGEN: This method call is required by the Web Form
Designer
''Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region

Protected Sub Page_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load, Me.Load
mySub()
End Sub
Sub mySub()
End Sub
End Class
End Namespace- Hide quoted text -


- Show quoted text -



re:
!This is what it says in myPage.aspx:
!<%@ Page Language="vb" AutoEventWireup="false"
!Does it mean that it is set to False ?

Yes, it is set to false.

re:
How can I eliminate the Handles statement ?

Since you already have AutoEventWireup set to false, all you have to do is eliminate
the double-loading of the code base. i.e., you currently have this :

Protected Sub Page_Load(...) Handles MyBase.Load, Me.Load

That loads the code twice ( once with MyBase.Load and again with Me.Load )
In ASP.NET 1.1 you could get away with that, but 2.0 is a bit stricter.

Use :
Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load

If you set AutoEventWireup to true, you wouldn''t need the Handles method, and you could use :

Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en espa?ol : http://asp.net.do/foros/
===================================
<fi**********@gmail.comwrote in message
news:11**********************@u30g2000hsc.googlegr oups.com...
Thank you for your reply.

>Are you setting AutoEventWireup to true ?

Do I find this in the myPage.aspx ?
This is what it says in myPage.aspx:
<%@ Page Language="vb" AutoEventWireup="false"
Inherits="Auction.WebForm1" CodeFile="myPage.aspx.vb" %>
I do not define/change it, it is like that already. Does it mean that
it is set to False ?

Test by setting AutoEventWireup to false, or by eliminating the Handles statement.

How can I eliminate the Handles statement ?

Thank you.
On Apr 29, 7:16 pm, "Juan T. Llibre" <nomailrepl...@nowhere.com>
wrote:

Are you setting AutoEventWireup to true
(or are you not defining it, since by default it is true) ?

Page events are automatically bound to methods that use the naming convention of
Page_event, such as Page_Load, when you set AutoEventWireup to true or not set it to false.

If you set AutoEventWireup to true, and then use the Handles statement,
you will get Page events called twice, once by AutoEventWireup,
and again when you use Handles.

Test by setting AutoEventWireup to false, or by eliminating the Handles statement.

Juan T. Llibre, asp.net MVP
asp.net faq :http://asp.net.do/faq/
foros de asp.net, en espa?ol :http://asp.net.do/foros/
===================================

<fiefie.ni...@gmail.comwrote in message

>
news:11**********************@c35g2000hsg.googlegr oups.com...
I am using ASP.NET 2005 and I have a simple form. Page_Load calls a
sub mySub that does not do anything (for testing purposes). But,
Page_Load gets called twice.
On every single ASPX page in my site, Page_Load gets called twice. Why
is that and how can I fix this problem ?
Thank you very much.

Imports System.IO
Namespace myProject
Partial Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents HyperLink1 As
System.Web.UI.WebControls.HyperLink

#Region " Web Form Designer Generated Code "
''This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
End Sub

Private Sub Page_Init(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Init
''CODEGEN: This method call is required by the Web Form
Designer
''Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region

Protected Sub Page_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load, Me.Load
mySub()
End Sub
Sub mySub()
End Sub
End Class
End Namespace- Hide quoted text -


- Show quoted text -