translate VB -> CS

Discussion in 'ASP .Net' started by Eirik Eldorsen, Jul 15, 2004.

  1. Could someone please help me translate this into C#?

    Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles MyBase.PreRender



    Eirik Eldorsen
    Eirik Eldorsen, Jul 15, 2004
    #1
    1. Advertising

  2. "Eirik Eldorsen" <> wrote in message
    news:%...
    > Could someone please help me translate this into C#?
    >
    > Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles MyBase.PreRender
    >
    >
    >
    > Eirik Eldorsen
    >
    >

    Here's something you could try (the free demo):

    http://www.tangiblesoftwaresolutions.com/

    I'm not affiliated with the company.

    --
    Peter [MVP Visual Developer]
    Jack of all trades, master of none.
    Peter van der Goes, Jul 15, 2004
    #2
    1. Advertising

  3. I could help you translate it, and I will, but I have to wonder what good
    it's going to do you? One line of code does not a programmer make. If you
    want to program in C#, I would suggest learning it. That said...

    private void Page_PreRender(Object sender, System.EventArgs Val)

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Eirik Eldorsen" <> wrote in message
    news:#...
    > Could someone please help me translate this into C#?
    >
    > Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles MyBase.PreRender
    >
    >
    >
    > Eirik Eldorsen
    >
    >
    Kevin Spencer, Jul 15, 2004
    #3
  4. Eirik Eldorsen

    Teemu Keiski Guest

    Hi,

    C# has no equivalent to VB's Handles statement, instead you need to wire the
    event handler explicitly. To follow the event handler practise, you do it
    like this:

    1. Create the event handler method
    ========================
    private void Page_PreRender(object sender, EventArgs e)
    {
    // Code goes here
    }

    2. Wire the event handler
    =================
    protected override void OnInit(EventArgs e)
    {
    base.OnInit(e);
    this.PreRender += new System.EventHandler(this.Page_PreRender);
    }

    Bit simpler way is to just override Page's OnPreRender method when all the
    code you need is:
    ================================================================
    protected override void OnPreRender(EventArgs e)
    {
    base.OnPreRender (e);
    //Code goes here
    }

    This is works because these every steps in Page lifecycle (the corresponding
    events like Init, Load, PreRender) have corresponding On<EventName> method
    (in Page/Control class) which is overridable (virtual in another words).
    This also means that no explicit event wiring is needed.

    Idea behind this is that with standard event pattern there's always this
    overridable On<EventName> method which actually raises the event and when
    you override the method your overriding method is guaranteed to run at this
    time, but it is then important to remember to call the base class method
    (the first line in my example) so that the event will originally be raised
    (because it is raised by the base class method) and again the wired event
    handlers (which the first example demonstrates as wiring one such) will be
    executed.

    Here is about the event pattern to give you the background information for
    what I explained
    http://msdn.microsoft.com/library/d...ide/html/cpconprovidingeventfunctionality.asp

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke



    "Eirik Eldorsen" <> wrote in message
    news:%...
    > Could someone please help me translate this into C#?
    >
    > Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles MyBase.PreRender
    >
    >
    >
    > Eirik Eldorsen
    >
    >
    Teemu Keiski, Jul 15, 2004
    #4
  5. The signature for the method is this:

    private void Page_PreRender(Object sender, EventArgs e)
    {
    }

    But, you have to create the event handler too:

    this.PreRender += new System.EventHandler(this.Page_PreRender);


    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    ************************************************
    Think Outside the Box!
    ************************************************
    "Eirik Eldorsen" <> wrote in message
    news:%...
    > Could someone please help me translate this into C#?
    >
    > Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles MyBase.PreRender
    >
    >
    >
    > Eirik Eldorsen
    >
    >
    Cowboy \(Gregory A. Beamer\) [MVP], Jul 15, 2004
    #5
  6. I know C#. The problem is that I don't know VB. I'm translating a small
    example.
    What I did'nt understand in the VB code was:

    "Kevin Spencer" <> wrote in message
    news:...
    > I could help you translate it, and I will, but I have to wonder what good
    > it's going to do you? One line of code does not a programmer make. If you
    > want to program in C#, I would suggest learning it. That said...
    >
    > private void Page_PreRender(Object sender, System.EventArgs Val)
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > Big things are made up
    > of lots of little things.
    >
    > "Eirik Eldorsen" <> wrote in message
    > news:#...
    > > Could someone please help me translate this into C#?
    > >
    > > Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
    > > System.EventArgs) Handles MyBase.PreRender
    > >
    > >
    > >
    > > Eirik Eldorsen
    > >
    > >

    >
    >
    Eirik Eldorsen, Jul 15, 2004
    #6
  7. I know C#. The problem is that I don't know VB. I'm trying to translating a
    small
    example.
    What I did'nt understand in the VB code was:
    Handles MyBase.PreRender

    "Kevin Spencer" <> wrote in message
    > I could help you translate it, and I will, but I have to wonder what good
    > it's going to do you? One line of code does not a programmer make. If you
    > want to program in C#, I would suggest learning it. That said...
    >
    > private void Page_PreRender(Object sender, System.EventArgs Val)
    Eirik Eldorsen, Jul 15, 2004
    #7
  8. Eirik Eldorsen

    Teemu Keiski Guest

    Handles is VB's alternative way to wire event handler explicitly to the
    event.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke


    "Eirik Eldorsen" <> wrote in message
    news:...
    > I know C#. The problem is that I don't know VB. I'm trying to translating

    a
    > small
    > example.
    > What I did'nt understand in the VB code was:
    > Handles MyBase.PreRender
    >
    > "Kevin Spencer" <> wrote in message
    > > I could help you translate it, and I will, but I have to wonder what

    good
    > > it's going to do you? One line of code does not a programmer make. If

    you
    > > want to program in C#, I would suggest learning it. That said...
    > >
    > > private void Page_PreRender(Object sender, System.EventArgs Val)

    >
    >
    Teemu Keiski, Jul 15, 2004
    #8
  9. Eirik Eldorsen

    Jo Inferis Guest

    Cowboy (Gregory A. Beamer) [MVP] wrote:
    > But, you have to create the event handler too:
    >
    > this.PreRender += new System.EventHandler(this.Page_PreRender);


    Interestingly enough, you don't actually *have* to do this. At least not for
    fundamental event handlers such as Page_Load, Page_PreRender and Page_Init
    etc.

    I've found you can even call the handlers things like Page_load or
    Page_Prerender and they're still added to the list on the right events.

    I'm not sure whether this is documented behaviour or not...

    --
    jo inferis
    Jo Inferis, Jul 15, 2004
    #9
  10. Eirik Eldorsen

    Scott Allen Guest

    Yes, this happens when the AutoEventWireup attribute is set to true
    in the @Page directive. You would not want to set AutoEventWireup to
    true and also add the event with code, the event will fire twice.

    --
    Scott
    http://www.OdeToCode.com


    On Thu, 15 Jul 2004 17:59:49 +0100, "Jo Inferis"
    <> wrote:

    >Cowboy (Gregory A. Beamer) [MVP] wrote:
    >> But, you have to create the event handler too:
    >>
    >> this.PreRender += new System.EventHandler(this.Page_PreRender);

    >
    >Interestingly enough, you don't actually *have* to do this. At least not for
    >fundamental event handlers such as Page_Load, Page_PreRender and Page_Init
    >etc.
    >
    >I've found you can even call the handlers things like Page_load or
    >Page_Prerender and they're still added to the list on the right events.
    >
    >I'm not sure whether this is documented behaviour or not...
    Scott Allen, Jul 15, 2004
    #10
  11. Ah! Understood! Makes much more sense.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Eirik Eldorsen" <> wrote in message
    news:...
    > I know C#. The problem is that I don't know VB. I'm translating a small
    > example.
    > What I did'nt understand in the VB code was:
    >
    > "Kevin Spencer" <> wrote in message
    > news:...
    > > I could help you translate it, and I will, but I have to wonder what

    good
    > > it's going to do you? One line of code does not a programmer make. If

    you
    > > want to program in C#, I would suggest learning it. That said...
    > >
    > > private void Page_PreRender(Object sender, System.EventArgs Val)
    > >
    > > --
    > > HTH,
    > > Kevin Spencer
    > > .Net Developer
    > > Microsoft MVP
    > > Big things are made up
    > > of lots of little things.
    > >
    > > "Eirik Eldorsen" <> wrote in

    message
    > > news:#...
    > > > Could someone please help me translate this into C#?
    > > >
    > > > Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
    > > > System.EventArgs) Handles MyBase.PreRender
    > > >
    > > >
    > > >
    > > > Eirik Eldorsen
    > > >
    > > >

    > >
    > >

    >
    >
    Kevin Spencer, Jul 15, 2004
    #11
  12. Eirik Eldorsen

    Jo Inferis Guest

    Scott Allen wrote:
    > Yes, this happens when the AutoEventWireup attribute is set to true
    > in the @Page directive. You would not want to set AutoEventWireup to
    > true and also add the event with code, the event will fire twice.


    Hmm...perhaps there's something odd about my installation then?

    I always explicitly use AutoEventWireUp="False", and it *still* works.

    --
    jo inferis
    Jo Inferis, Jul 17, 2004
    #12
  13. Eirik Eldorsen

    Scott Allen Guest

    The only other option is that Visual Studio .Net will automatically
    wire up the Page_Load event for you in " Web Form Designer generated
    code" region of the the code behind. I'm not sure how you could
    automatically be getting the PreRender event.

    --s

    On Sat, 17 Jul 2004 10:07:08 +0100, "Jo Inferis"
    <> wrote:

    >Scott Allen wrote:
    >> Yes, this happens when the AutoEventWireup attribute is set to true
    >> in the @Page directive. You would not want to set AutoEventWireup to
    >> true and also add the event with code, the event will fire twice.

    >
    >Hmm...perhaps there's something odd about my installation then?
    >
    >I always explicitly use AutoEventWireUp="False", and it *still* works.


    --
    Scott
    http://www.OdeToCode.com
    Scott Allen, Jul 17, 2004
    #13
  14. Eirik Eldorsen

    Th4tch

    Joined:
    Sep 7, 2007
    Messages:
    1
    My god, it was a question, they didn't want a lecteur.
    Th4tch, Sep 7, 2007
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sridhar Hegde
    Replies:
    2
    Views:
    2,504
    Ajeetha Kumari
    Sep 13, 2004
  2. Rakesh Sharma
    Replies:
    2
    Views:
    2,888
    Thomas Rudloff
    Oct 22, 2004
  3. Nisheeth

    post translate simulation

    Nisheeth, Apr 29, 2005, in forum: VHDL
    Replies:
    2
    Views:
    839
    Mike Treseler
    Apr 29, 2005
  4. Replies:
    3
    Views:
    599
    Bert Cuzeau
    Jun 22, 2005
  5. Replies:
    1
    Views:
    581
Loading...

Share This Page