ASPNET 3.0 newbie question

  • Thread starter Thread starter ckkwan
  • Start date Start date
C

ckkwan

My VS2008 just arrive.

One very dumb question, how to subscribe to event like Page_Init?

I can't find it anywhere in the IDE. Ended up have to type in myself.

TIA
 
If using VB, open your code-behind page in the IDE,
select (Page Events) from the left-hand dropdown,
and then select Init from the right-hand dropdown.

The IDE will write this :

Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

End Sub

If you are coding in C#, enter the Page_Init event handler using this code :

private void Page_Init(object sender, EventArgs e)

{

}

The IDE won't write anything for you.



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
 
Just for the information , since you are newbie.

You might be wondering how this method definition is magically being linked
to Page's Init event, look at the directive
AutoEventWireUp
 
Precisely, I used to be able to do this in VS2003.

But now I am not able to do it anymore in VS2008 :(

I just received my VS2008 last week.
 
Yes, I think the AutoEventWireUp is the clue.

And Since I jump from VS2003 to VS2008. I didn't aware something that
had changed since 2005.

It seems like it had been like this since VS2005. Where VB.NET can
select the object and event for page events, but in C# we have to
explicitly type the event handler method. :(
 
re:
!> Where VB.NET can select the object and event for page events,
!> but in C# we have to explicitly type the event handler method.

Here's the trick...

In both VS 2005 and VS2008 :

If you use inline code, whether C# or VB.NET, you don't have to type the event handler method.
If you use code-behind in C#, you do have to type the event handler method.
If you use code-behind in VB.NET, you don't have to type the event handler method.

In C#, if you configured <pages autoEventWireup , in web.config, to "true":


<system.web>
<pages autoEventWireup="true" />
</system.web>

and then, if you select an inline code page in a VS 2005/2008 C# project,
select "Page" from the dropdown "Server Objects and Events"
and select "Init" from the right-hand dropdown, the IDE writes this :

<script runat="server">
protected void Page_Init(object sender, EventArgs e)
{

}
</script>

If you select "place code in separate file" (code-behind),
neither of the 2005/2008 IDEs list the Page Events.

However, in both VS 2005 and 2008, when using VB.NET,
you don't need to set <pages autoEventWireup to "true"
in web.config in order to be able to select Events in the IDE.





Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
Yes, I think the AutoEventWireUp is the clue.

And Since I jump from VS2003 to VS2008. I didn't aware something that
had changed since 2005.

It seems like it had been like this since VS2005. Where VB.NET can
select the object and event for page events, but in C# we have to
explicitly type the event handler method. :(
 
Back
Top