Best way to create Page_PreRender in VB.Net

W

windsurfing_stew

Hi,

Quick question. What's the best way to create the handler for
Page_Prerender in ASP.Net 2.0. I used to just use the dropdowns to
select (Page Events) on the left and choose PreRender in the right hand
dropdown. Now however these are not listed.

Any recommendations?

Stew
 
K

Karl Seguin

In vb.net there's always three ways to implement a base method. There are
some minor diferences between then (not functionality though). I'd pick the
one the most consistant with how you do it within the rest of your system.

1 - (the way I guess you probably want it)
Protected Sub Page_PreRender(ByVal s As Object, ByVal e As EventArgs)
Handles Me.PreRender
'code here
End Sub


2 -
Protected Overrides Sub onPreRender(ByVal e As System.EventArgs)
'code here
MyBase.OnPreRender(e)
End Sub


3 -
'put this in Init or somwhere
AddHandler Me.PreRender, AddressOf Page_PreRender2

Protected Sub Page_PreRender2(ByVal sender As Object, ByVal e As
System.EventArgs)
'code here
End Sub

Karl
 
W

windsurfing_stew

Hi Karl,

Thanks for your response. I was actually more interested in how you do
this through the IDE. I used to be able to create handlers like
Page_PreRender by using the two dropdowns above the code.

Thoughts?
 
A

albert braun

Stew,

Maybe you want the TAB complete functionality in VS.NET ?

Inside your page's Page_Load method, you can type:

this.PreRender +=

and then you should see Intellisense telling you to hit the TAB key for
autocomplete functionality. You hit TAB the first time and it completes
your statement by appending:

new EventHandler(_Default_PreRender);

Then, you hit TAB a second time, and the IDE inserts a new
corresponding method body below:

void _Default_PreRender(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}

Then you just replace the Exception throwing statement with your
desired code.
(Note: in this case, my page class is named _Default, so your method
name may vary).

Hope that helps.

Regards,
Albert Braun
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top