Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Page Initialize Event in C#

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Resolved [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.

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Mobile, AL, USA
    Posts
    600

    Thumbs up gep13 ....

    Just what I was looking for .... thanks!

    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.
    I'm doing some processing of all the controls on a page that inherit from my custom page. By putting this processing in my custom page and inheriting from it, I can do all of the processing in one place.

    Thanks again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width