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