Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > translate VB -> CS

Reply
Thread Tools

translate VB -> CS

 
 
Eirik Eldorsen
Guest
Posts: n/a
 
      07-15-2004
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


 
Reply With Quote
 
 
 
 
Peter van der Goes
Guest
Posts: n/a
 
      07-15-2004

"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.


 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      07-15-2004
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
>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      07-15-2004
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/de...ctionality.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
>
>



 
Reply With Quote
 
Cowboy \(Gregory A. Beamer\) [MVP]
Guest
Posts: n/a
 
      07-15-2004
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
>
>



 
Reply With Quote
 
Eirik Eldorsen
Guest
Posts: n/a
 
      07-15-2004
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
> >
> >

>
>



 
Reply With Quote
 
Eirik Eldorsen
Guest
Posts: n/a
 
      07-15-2004
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)



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      07-15-2004
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)

>
>



 
Reply With Quote
 
Jo Inferis
Guest
Posts: n/a
 
      07-15-2004
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


 
Reply With Quote
 
Scott Allen
Guest
Posts: n/a
 
      07-15-2004
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...


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Post Translate Timing yaseenzaidi@NETZERO.com VHDL 3 06-22-2005 06:12 AM
post translate simulation Nisheeth VHDL 2 04-29-2005 05:36 PM
translate this send into perl sfgroups@gmail.com Perl 1 03-16-2005 09:54 PM
Xilinx translate error : Cannot find signal "clk" Rakesh Sharma VHDL 2 10-22-2004 08:03 PM
Modelsim post place and route/Post Translate issues Sridhar Hegde VHDL 2 09-13-2004 02:43 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57