473,503 Members | 9,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

translate VB -> CS

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
Nov 18 '05 #1
12 1315

"Eirik Eldorsen" <NO************@eldorsens.nettsider.no> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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.
Nov 18 '05 #2
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" <NO************@eldorsens.nettsider.no> wrote in message
news:#J**************@TK2MSFTNGP10.phx.gbl...
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

Nov 18 '05 #3
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" <NO************@eldorsens.nettsider.no> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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

Nov 18 '05 #4
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" <NO************@eldorsens.nettsider.no> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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

Nov 18 '05 #5
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" <ks******@takempis.com> wrote in message
news:ue**************@TK2MSFTNGP12.phx.gbl...
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" <NO************@eldorsens.nettsider.no> wrote in message
news:#J**************@TK2MSFTNGP10.phx.gbl...
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


Nov 18 '05 #6
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" <ks******@takempis.com> 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)

Nov 18 '05 #7
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" <NO************@eldorsens.nettsider.no> wrote in message
news:uH*************@TK2MSFTNGP10.phx.gbl...
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" <ks******@takempis.com> 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)


Nov 18 '05 #8
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
Nov 18 '05 #9
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"
<in*****@NOSPAM.gotadsl.co.uk> 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...


Nov 18 '05 #10
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" <NO************@eldorsens.nettsider.no> wrote in message
news:ub**************@tk2msftngp13.phx.gbl...
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" <ks******@takempis.com> wrote in message
news:ue**************@TK2MSFTNGP12.phx.gbl...
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" <NO************@eldorsens.nettsider.no> wrote in message news:#J**************@TK2MSFTNGP10.phx.gbl...
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



Nov 18 '05 #11
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
Nov 18 '05 #12
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"
<in*****@NOSPAM.gotadsl.co.uk> 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
Nov 18 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2320
by: Bengt Richter | last post by:
Just thought None as the first argument would be both handy and mnemonic, signifying no translation, but allowing easy expression of deleting characters, e.g., s = s.translate(None,...
1
2013
by: shank | last post by:
I'm sure this is a stretch, but is there some kind of component that I could install to translate from English to Spanish on the fly? I have a lot of equipment features and specifications that I...
4
2136
by: Gadrin77 | last post by:
I have data that looks like <Root> <Main Value="Line1|Line2.|Line3|Line4.|Line5"/> </Root> I'm using Translate(@Value, "|.", ",")
6
2732
by: bobueland | last post by:
The module string has a function called translate. I tried to find the source code for that function. In: C:\Python24\Lib there is one file called string.py I open it and it says
6
5538
by: Anders K. Olsen | last post by:
Hello group I'm trying to list the users and groups who has read access to a file. I use .NET 2.0 and FileInfo.GetAccessControl().GetAccessRules(...) and then loop through the...
1
9369
by: peterbe | last post by:
This has always worked fine for me. Peter fine Now if I do it with a unicode string: Traceback (most recent call last): File "<stdin>", line 1, in ? File "/usr/lib/python2.4/string.py", line...
9
3084
bvdet
by: bvdet | last post by:
I have done some more work on a simple class I wrote to calculate a global coordinate in 3D given a local coordinate: ## Basis3D.py Version 1.02 (module macrolib.Basis3D) ## Copyright (c) 2006...
1
2542
by: =?Utf-8?B?R2F1cmF2?= | last post by:
Hi, I am using the Translate() function in one of the .XSLT file to remove the spaces, like this: <xsl:for-each select=".//Illustration"> <xsl:value-of select="translate(./@illusName, ' ',...
3
4689
by: Kenneth McDonald | last post by:
I have the need to occasionally translate a single word programatically. Would anyone have a Python script that would let me do this using Google (or another) translation service? Thanks, Ken
4
10615
by: kovariadam | last post by:
Hi, Does anybody know why i get this error: SQL0176N The second, third or fourth argument of the TRANSLATE scalar function is incorrect. SQLSTATE=42815 with this query: SELECT...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7294
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7361
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.