Calling Events on Standard Controls Programmatically

99 views
Skip to first unread message

MrSco...@gmail.com

unread,
Jun 9, 2008, 3:22:45 AM6/9/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi All,

I want to know, if there is any way to raise an event of a standard
control programmatically. Scenario is that I want to raise the click
event of a button control upon changing the text of a text box
control. How can I do that?

Thanks in Advance.
Happy Programming!
Adeel.

Andrew Badera

unread,
Jun 9, 2008, 1:27:31 PM6/9/08
to DotNetDe...@googlegroups.com
Just call the handler and pass it the appropriate references. Yes, it really is just that easy.
--
--
--Andy Badera
http://higherefficiency.net
http://flipbitsnotburgers.blogspot.com/
http://andrew.badera.us/
http://changeroundup.com/
and...@badera.us
(518) 641-1280
Google me: http://www.google.com/search?q=andrew+badera

Glenn

unread,
Jun 9, 2008, 1:28:37 PM6/9/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Simply call your event handler that you've set up for the button.

...Glenn

On Jun 9, 3:22 am, "mrscorp...@gmail.com" <MrScorp...@gmail.com>
wrote:

MrSco...@gmail.com

unread,
Jun 10, 2008, 3:26:11 AM6/10/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi,

Thanks for your response. It was kind of you.
But call to the handler is not raising event. My statement was I want
to raise event i.e. button automatically calls handler once I raise
event on that button. Just wondering if it is possible to raise events
on the controls.

I feel my example previously was not good enough to make it clear as
to what exactly i want. Let me explain the exact scenario as to why I
need raising event.
I have developed a custom button control which is derived from Control
class. My control fires click event upon clicking but I also want to
fire click event when user presses enter or space key on that
control.
Currently I have solved my problem by implementing my own event
ButtonClick, which I fire each time when someone clicks or presses
space or enter key. But I don't want two events like Click or
ButtonClick, I just want one event and that is Click event, which is
the already there in Control class. How to fire that event of that
super class upon keypress?

Thanks in Advance.
Happy Programming!
Adeel.


On Jun 9, 10:27 pm, "Andrew Badera" <and...@badera.us> wrote:
> Just call the handler and pass it the appropriate references. Yes, it really
> is just that easy.
>
> On Mon, Jun 9, 2008 at 3:22 AM, mrscorp...@gmail.com <MrScorp...@gmail.com>
> wrote:
>
>
>
> > Hi All,
>
> > I want to know, if there is any way to raise an event of a standard
> > control programmatically. Scenario is that I want to raise the click
> > event of a button control upon changing the text of a text box
> > control. How can I do that?
>
> > Thanks in Advance.
> > Happy Programming!
> > Adeel.
>
> --
> --
> --Andy Baderahttp://higherefficiency.nethttp://flipbitsnotburgers.blogspot.com/http://andrew.badera.us/http://changeroundup.com/

Andrew Badera

unread,
Jun 10, 2008, 2:19:21 PM6/10/08
to DotNetDe...@googlegroups.com
Just register multiple handlers with said event.

Glenn

unread,
Jun 11, 2008, 9:32:41 AM6/11/08
to DotNetDe...@googlegroups.com
If you have a custom class based on the Control class, then the event that is triggered is for your class, not the Control class.  You can, however, call the base class' event handler as part of your event handler.
 
After you implement the processing you want, simply register the event handler for all the events you want to execute that code.
 
...Glenn

 

Adeel

unread,
Jun 11, 2008, 12:52:46 PM6/11/08
to DotNetDe...@googlegroups.com
Hi,

First of all thank you for your input.
What you are suggesting is to register a handler with event. That will only execute the code I've written in the handler while implementing that control but will not raise the click event on my custom control i.e. the code written by user of the control in the click event handler  at design time will not be called, because handler is being called whenever click event is raised, but my problem is to raise event upon key press and that click event handler code written by the user of the control at design time should also run upon that key press.

But my problem is solved now. I just wanted to share how I solved the problem so it maybe helpful for others as well.

I called the OnClick method of the Control class to raise click event upon keypress i.e. upon pressing enter or space when control is in focus. This way click event is raised for the control so that the click event handler written by the user of the control at design time is also executed each time some one presses space bar or enter key when this control is in focus, not just the handler which is written inside the implementation of control.

I hope I've made my point clear.

Thank you all for your input.
Happy Programming!
Adeel.
Reply all
Reply to author
Forward
0 new messages