Page_Load

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>
 
F

Felix Wu [MSFT]

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.


--------------------
 

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

Top