C# Event Code

A

AG

Using VS 2005.

Usually I work in VB.NET.
In code behind when I need to add code to an event, I just select the object
in the upper left dropdown of the code window and then the desired event in
the upper right dropdown and the IDE builds the sub.

I am currently working on a project where the code behind is in C# and the
above functionality is not available.
Consequently, I find myself searching the web for the corrent arguments,
etc. for various control and page events.
The help files show few or none.

E.G.
protected void FormView1_ItemInserting(object sender,
FormViewInsertEventArgs e)
{
}

There must be an easier way to get this.
Can anyone advise or provide a link where one can find the format,
parameters, etc. for control events.
 
S

Steven Cheng[MSFT]

Hello AG,

As for the C# development IDE, it does be a bit different from the VB.NET
IDE since they'are all customized according to the programming preference
of developers(or the language characteristics).

When you wang to register and event handler for an ASP.NET web control in
codebehind through Visual C# IDE, you can follow the following steps:

1. Switch to design view of the page, and select the certain control

2. Keep the control selected and go to the "properties window"

3. In the properties window, click the event tab(with a lighting icon),
then you'll see all the available events of the control

4. double click the certain event in the list to add a event handler in
codebehind(or you can select and existing handler functino from the
dropdownlist)

Here is the MSDN reference which detailedly describe this:

#How to: Create Event Handlers in ASP.NET Web Pages (Visual Studio)
http://msdn2.microsoft.com/en-gb/library/6w2tb12s(VS.80).aspx

BTW, for page events, the above rule doesn't apply. You need to directly
add the "Page_XXXX" handler function in codebehind (such as Page_Load,
Page_PreRender) and the runtime compiler will automatically wire it up.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

AG

Thanks Steven,

That is exactly what I needed. Don't know why I did not see that lightning
bolt. For that matter I don't know why it is not easy to find that info
using Help.
Do you have a link that shows all the correct parameters for the various
page events?

--

AG
Email: discuss at adhdata dot com
 
P

Patrick

I have been learning ASP.NET over the last few months and this exact same
issue drove me copmletely crazy. I never saw that lightning bolt. Thanks!!!
 
S

Steven Cheng[MSFT]

Thanks for your reply AG,

Sure, you can first search the Page class in MSDN and locate all its events:

#Page Events
http://msdn2.microsoft.com/en-us/library/2xz770y8.aspx

On the above page, you can click into each individual event and check their
eventhandler type. And the eventhandler type should contains the correct
signature. You can use your local MSDN since that'll be much quicker.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

AG

The keyword here is 'should'.
I followed the link and yes, it is the same content as my local MSDN, but I
don't see any signatures.

When I click on Load, I would expect to see something like
protected void Page_Load(object sender, EventArgs e)

Instead I get

public event EventHandler Load
and an example of

// This is the constructor for a custom Page class.
// When this constructor is called, it associates the Control.Load event,
// which the Page class inherits from the Control class, with the Page_Load
// event handler for this version of the page.
public MyPage()
{
Load += new EventHandler(Page_Load);
}

Not very useful for purposes of this discussion.
 
S

Steven Cheng[MSFT]

Thanks for your reply AG,

I've got your actual concern here. Yes, as you noticed, there hasn't an
existing list of all the page events' declare syntax such as:

Page_Load.....
Page_PreRender....

Actually, so far what we have are the following document:

**all the page events' name (this determine the event handler function's
name)

**all the page events' handler type(this determine the event handler
function's parameter/return type signature).

For example, when you want to add event handler for asp.net page in C#
codebehind, you first get its event name, suppose it is "PreRender", then
it is determined that the event handler function's name should be
"Page_PreRender". After that, you also get event's handler type, it is of
"EventHandler" delegate type(from the msdn reference I refered in previous
reply), so you further determine that you need to author the event handler
functiton as below:

void Page_PreRender(object sender, EventArgs e)
{

}

this is the same for other page events e.g.

void Page_PreInit(object sender, EventArgs e){...}
void Page_Init(object sender, EventArgs e){...}
void Page_Load(object sender, EventArgs e){...}
..............


BTW, the above function declare is used when you are set
AutoEventWireup=True for your page, in such case, ASP.NET runtime compiler
will automatically associate those handler funcion(with the
"Page_eventname" naming convention) to the correct Page event. If
"AutoEventWireup" is turn off, you need to explicily register event
handler, such as the following means you mentioned:

public MyPage()
{
Load += new EventHandler(Page_Load);
}

Here is another MSDN reference covers some non-IDE related info about
dealing with event handling of ASP.NET web controls and page:

#ASP.NET Web Server Control Event Model
http://msdn2.microsoft.com/en-us/library/y3bwdsh3.aspx

In addition, I think your feedback on the event documentation is really
reasonable and I recommend you add comments on the MSDN reference page
directly or send feedback to our product center:

http://connect.microsoft.com/feedback/default.aspx?SiteID=210

Hope this helps some further. If there is anything else we can help, please
feel free to let me know.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

AG

Thanks Steven,

I think you made my point. Help is of little help!
It would be easier for me and developers like me to simply create a page in
a VB project, get all the page events, convert to C# and add to code
sniplets.
 
S

Steven Cheng[MSFT]

Thanks for the followup.

Yes, code convertion between different languages does be a common problem.
As far as I know, the product team may want to leave more space for some
other 3rd party ISV or community on this. Anyway, it is also really welcome
to get such feedback from customers.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

AndyW

The keyword here is 'should'.
I followed the link and yes, it is the same content as my local MSDN, but I
don't see any signatures.

I might highlight the fact that the operative word 'should' be
underlined.

After nearly 30 years of development I find the current help system
(especially the offline side of things) to be probably the worst that
I have ever used and not at all condusive for new (or even old)
developers.

Now there is so much clutter on the help pages, links are all over the
place and often you have to scroll down well past the end of the page
to find the basic overview links.

Gone are the days when one could jus hit F1 on a keyword, have the
help come up with what the keyword is does (in relation to its class)
and have some examples.

Now I have to have a degree in obfustication just to get past the "How
do I" rubbish or the "index" filters that seem to be heavily dyslexic.
Not only that, but if I hit f1 on a mehod name, I get an error stating
it cant find any help because it didnt understand what the instance
name is. I wonder who the person was that came up with the idea to
allow a help system to search on instance names (variable names).

ps. 90% of my development/work is done - not connected to the
internet (including using Office programs) and the like. So its
really annoying when help systems assume one has access to it.
 

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,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top