Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

c# custom control (overriding OnClick problem)

377 views
Skip to first unread message

David Vella

unread,
Apr 6, 2002, 10:26:52 AM4/6/02
to
I have made a small custom control derived from
System.Web.UI.WebControls.Button.

This overrides the OnClick and alters its Text property to show HELLO
when clicked. This worked perfectly and the code is shown below.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace CustomControls
{
public class mybutton : System.Web.UI.WebControls.Button
{
public mybutton( )
{
this.Text = "Push Here";
}
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
this.Text = "Hello";
}
}
}


I added the mybutton to the ToolBox and then dragged it on a clean c#
ASP.NET web form. It works when clicked with the mouse but if I try to
invoke it using :

this.Mybutton1_Click(sender,e);

it just ignores my override code, and the HELLO is not shown. WHY ???

What should I be doing to trigger the mybutton OnClick event (of the
instance MyButton1) programatically ?

Thanks

David Vella
Malta

walter

unread,
Apr 6, 2002, 10:53:14 AM4/6/02
to
have you checked its events ?


David Vella

unread,
Apr 6, 2002, 11:22:18 AM4/6/02
to

Could you please be more specific, I presume that the answer lies in how
to trigger and simulate a Click Event as if the user have clicked the
button with a mouse.

David

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

walter

unread,
Apr 6, 2002, 11:46:35 AM4/6/02
to
how do you call the eventHandler ?
why do you call the eventHandler in the first place ?
why not just setting this.Text = "Hello" ?

David Vella

unread,
Apr 7, 2002, 1:22:22 AM4/7/02
to
You are missing the point. The example is intentionally easy to
replicate, but its just an example which might be much more complex if
required.

So my question is, how can one trigger an event of any custom web
control programatically ?


Regards

David Vella

walter Angioletti

unread,
Apr 7, 2002, 1:46:15 AM4/7/02
to
is the example also intentionally wrong ?
your OnClick is not an event handler, you should show us correct code to
start with.

walter easy

David Vella

unread,
Apr 7, 2002, 4:14:27 AM4/7/02
to
No the code is correct, try it. It is overriding the normal button
OnClick so I need not do a custom event.


Regards

David Vella

0 new messages