Page_Load

  • Thread starter Thread starter A.M
  • Start date Start date
A

A.M

Hi,

Why in the following page, word ABC is being appear twice?

Thanks,
Ali

<%@ Page %>
<HTML>
<HEAD>
<title>test</title>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not Me.IsPostback Then
Response.Write("ABC" + "<br>" )
end if
End Sub
</script>
</HTML>
 
Hi A.M,

You do not need to explicitly register the event handler Page_Load to the
Load event because it is registered by default:

<%@ Page %>
<HTML>
<HEAD>
<title>test</title>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
If Not Me.IsPostback Then
Response.Write("ABC" + "<br>" )
end if
End Sub
</script>
</HTML>

Actually, this behavior is controlled by the AutoEventWireup attribute in @
Page directive. This attribute indicates whether the page's events are
autowired. "true" if event autowiring is enabled; otherwise, false. The
default is true. If you disable it, "ABC" only is displayed once:

<%@ Page AutoEventWireup=False%>
<HTML>
<HEAD>
<title>test</title>
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Me.IsPostback Then
Response.Write("ABC" + "<br>" )
end if
End Sub
</script>
</HTML>

Regards,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 
Back
Top