Sub Method Page_Init: init event could not be found

The following method returns an error: "The init event could not be found" and get an error in System.Web.UI.Page

Visual Studio 2010, framework 3.5

Public Class_default Inherits System.Web.UI.Page Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init End Sub 
+4
source share
4 answers

I am not a VB.NET expert (I write in C #), but I can say that the cause of the problem is that you need to override the OnInit method instead of the Page_Init parameter.

So you need to use the following code:

 Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load End Sub Protected Friend Overrides Sub OnInit(ByVal e As EventArgs) MyBase.OnInit(e) End Sub End Class 
+4
source

I think Maxim is right, however you can also add an event handler by doing:

 AddHandler Me.Init, AddressOf Page_Init 

I think that's right, sorry, my VB is pretty rusty.

+1
source

Well,

I assume that you are using AutoEventWireup="true" in your markup, but you also marked your handler with the Handles .

AutoEventWireup will not work, it will not be able to directly access the private members of your class.

Set AutoEventWireup="false" and save the unnecessary performance limitation , the handler should still fire because it explicitly Handles event.

Since you are handling the event explicitly, you can also change the name of the event handler and remove the ugly _ .

+1
source

Most of your Crystal Reports code is most likely present in the Page_Load event. If you move it to Page_Init, you will find that it is working correctly.

0
source

Source: https://habr.com/ru/post/1445548/


All Articles