[RESOLVED] [2005] Page Initialize Event in C#
Hi,
I have some code in a VB project that I would like to use in C#. The code is for a page that inherits from System.Web.UI.Page but has no UI (no aspx page) but just has the class page. Specifically, I'm trying to handle the Page Initialize event. Here is how I do it in VB:
Code:
Private Sub CustomPage_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
DoStuff()
End Sub
I'm trying to do the same in C#, but the Init event doesn't fire:
Code:
private void CustomPage_Init(Object sender, EventArgs e)
{
DoStuff();
}
Is there anyway to get the page events in C# to fire without having to have a page file (aspx page) associated with the class file? I know the C# version of Handles Me.Init needs to be handled, but I don't know how to do this in C# for a class that inherits from System.Web.UI.Page but doesn't have an aspx page associated with the class file.
Re: [2005] Page Initialize Event in C#
Hey,
The first question would be why do you have a page that doesn't have any UI?!?! To me that doesn't make sense, unless I am missing something.
To answer your question though, you need to create the Event Handler for this, which would be something like:
Code:
this.Init += new EventHandler(CustomPage_Init);
Hope this helps!
Gary