ASPNET 3.0 newbie question

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
 
J

Juan T. Llibre

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

Madhur

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
 
S

sturyuu5eye

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

sturyuu5eye

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. :(
 
J

Juan T. Llibre

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.






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. :(
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top