473,703 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Event Handling c#


Hi,

I am currently learning c# so be gentle :)

I am converting a Delphi.NET website to c# website and I am confused as
to how events are handled.

2 Situations.

1. A component on a webusercontrol fires a postback event. On postback
the parent page handles that event and runs code specifically for that
page. So that the same event can run different code depending on what
page it is on.

2. A component on a webusercontrol fires a postback event and another
webusercontrol on that page recognises that event was fired and runs
its own method.
I hope this is enough information because I only know how it works in
Delphi.

Many Thanks
Jeremy
Feb 7 '07 #1
1 5360
Hi there,

You can handle an event only if you subscribed to it. Technically,
subscribing/handling means passing a method pointer to the event source:

Page.Load += new EventHandler(th is.Page_Load);

If you have programmed in C or C++ is similar to this

void* (*EventHandler) (object* source, EventArgs* e);
this.Load = &this.Page_Load ;

or if you programmed in Delphi Object Pascal it is equivalent to:

Page.Load := self.Page_Load;

I used similar because .NET events employ multicast delegates that are
‘collectionsâ €™ of method pointer so many subscribers can handle one event.
Anyway
>1. A component on a webusercontrol fires a postback event. On >postback the parent page handles that event and runs code >specifically for that page. So that the same event can run different >code depending on what page it is on.
Yes. Behind the scenes there’s always a statement that attaches event
handler to particular event. In ASP.NET 1.1, everything was explicitly
assigned in InitializeCompo nent() method. ASP.NET 2.0 (by default),
implicitly attaches event handlers for you based on naming convention and
AutoEventWireup @page attribute. For example, AutoEventWireup =true and page
compiler discovers there is a protected/public method called Page_Load(objec t
sender, EventArgs e), it automatically does assignment
Page.Load += new EventHandler(th is.Page_Load);
>2. A component on a webusercontrol fires a postback event and >another webusercontrol on that page recognises that event was fired >and runs its own method.
It doesn’t recognize, it just attaches an event handler as stated above.

Hope it’s clear now

Milosz

"Jeremy Martin" wrote:
>
Hi,

I am currently learning c# so be gentle :)

I am converting a Delphi.NET website to c# website and I am confused as
to how events are handled.

2 Situations.

1. A component on a webusercontrol fires a postback event. On postback
the parent page handles that event and runs code specifically for that
page. So that the same event can run different code depending on what
page it is on.

2. A component on a webusercontrol fires a postback event and another
webusercontrol on that page recognises that event was fired and runs
its own method.
I hope this is enough information because I only know how it works in
Delphi.

Many Thanks
Jeremy
Feb 7 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2830
by: DylanM | last post by:
I have some checkboxes that are generated from the results of a database search. At the moment, the checkboxes are part of a table making up a form. Users are going through the form, clicking the boxes and saving to the database at the end with the 'Submit' command button. Is it possible to save the changes as the checkboxes are clicked? I suppose I'd need to write some dynamic ASP event handling at the same time as creating the checkboxes......
1
20696
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function init() {
1
7582
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
6
1799
by: Steve Caliendo | last post by:
Hi, I'm creating 5 ImageButton controls in the panel control, and I have a unique ID specified for each one. When I click on any one of them, the Page_Load executes (Of course), but how do I know which ImageButton caused the post back ? Does it get handled in the Page_Load or do I need to create a new event handler ? Thanks,
3
3978
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which step you're on. This all works fine, but I ran into some trouble when I started creating controls dynamically in my code-behind file. Each panel contains a table which is filled with various radio buttons, text fields and the such which are...
2
3832
by: Developer_Software | last post by:
Thanks in advance to anyone who can help :) I've got a placeholder control WITHIN A USER CONTROL that has its contents dynamically added and removed at runtime by a regular .aspx page. At runtime, the placeholder control adds a dropdownlist where I would like it to redirect the user to a different page dependent on the selection they make from the dropdownlist. I've tried writing the delegate and the event handler both in the
7
2907
by: Christopher Pisz | last post by:
My problem is my derived class is getting called twice instead of the base and then the derived. I thought this was the purpose for virtuals and dynamic casting :/ I want my base class to have its method called and then the derived class have its method called. What am I not understanding? Int the following code, my Event Tester class is getting called twice for keyboard events when I step through the debugger:...
0
1344
by: =?Utf-8?B?SWRlcm9ja3M=?= | last post by:
Hi All, I created a dynamic checkbox in ASP .Net inside a Button1_Click event method (outside the page_load event) and performed the event handling method for the CheckedChanged event and I check the checkbox at runtime nothing happens (checkBoxObj.check is always false). Does anyone have information on how to make this work? Note: I can get it to work inside Page_Load event. I need help in getting it to work in different event...
1
6015
by: iderocks | last post by:
Hi All, I created a dynamic checkbox in ASP .Net inside a Button1_Click event method (outside the page_load event) and performed the event handling method for the CheckedChanged event and when I check the checkbox at runtime nothing happens (checkBoxObj.check is always false). Does anyone have information on how to make this work? Note: I can get it to work inside Page_Load event. I need help in getting it to work in a different event...
0
8662
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9243
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9109
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9002
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5922
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4420
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2434
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.