how to add events to custom control

G

Guest

Hi. I'm not getting any answers in buildingcontrols, so I'm gonna try here.

I've written a custom control derived from System.Web.UI.WebControls.ListControl. The control is taking in a dataset and renders HTML with radio buttons (the result is similar to a RadioButtonList). I would like to add events to the control, but being new to .NET I don't know where to start.
When the user changes selection by clicking another radio button, I would like to do a postback and process the selected data.
How do I do this?
Again, I have no idea even how to start and I couldn't find help on the MSDN Library.
Thanks
TIB
 
M

Marcos Santos \(MOS\)

Hi,

you have to declare an Event attribute and creating a subrotine that
contains the RaiseEvent statement like

Public Event Event1(s as Object, e As EventArgs)

subrotine:

Protected Sub OnEvent1(e As EventArgs)
RaiseEvent Event1(Me, EventArgs.Empty)
End Sub

and look the class IPostBackDataHandler that your class must inherit

Marcos Santos

TIBM said:
Hi. I'm not getting any answers in buildingcontrols, so I'm gonna try here.

I've written a custom control derived from
System.Web.UI.WebControls.ListControl. The control is taking in a dataset
and renders HTML with radio buttons (the result is similar to a
RadioButtonList). I would like to add events to the control, but being new
to .NET I don't know where to start.
When the user changes selection by clicking another radio button, I would
like to do a postback and process the selected data.
 
K

Kyril Magnos

And in C#,

public event EventHandler MyEvent;

protected void OnMyEvent(object sender, System.EventArgs e)
{
if(MyEvent != null)
{
MyEvent(sender, e);
}
}

public void TestEvent()
{
OnMyEvent(this, EventArgs.Empty);
}

--
HTH

Kyril Magnos

| Hi,
|
| you have to declare an Event attribute and creating a subrotine that
| contains the RaiseEvent statement like
|
| Public Event Event1(s as Object, e As EventArgs)
|
| subrotine:
|
| Protected Sub OnEvent1(e As EventArgs)
| RaiseEvent Event1(Me, EventArgs.Empty)
| End Sub
|
| and look the class IPostBackDataHandler that your class must inherit
|
| Marcos Santos
|
| "TIBM" <[email protected]> escreveu na mensagem
| | > Hi. I'm not getting any answers in buildingcontrols, so I'm gonna try
| here.
| >
| > I've written a custom control derived from
| System.Web.UI.WebControls.ListControl. The control is taking in a dataset
| and renders HTML with radio buttons (the result is similar to a
| RadioButtonList). I would like to add events to the control, but being new
| to .NET I don't know where to start.
| > When the user changes selection by clicking another radio button, I
would
| like to do a postback and process the selected data.
| > How do I do this?
| > Again, I have no idea even how to start and I couldn't find help on the
| MSDN Library.
| > Thanks
| > TIB
| >
|
|
 
D

Dale

Check out the documentation on RaisePostBackEvent method and
IPostBackEventHandler as well. You may want to capture the postback event
in your control, and raise the event that your page will see from within the
postback event of the control.

Dale

TIBM said:
Hi. I'm not getting any answers in buildingcontrols, so I'm gonna try here.

I've written a custom control derived from
System.Web.UI.WebControls.ListControl. The control is taking in a dataset
and renders HTML with radio buttons (the result is similar to a
RadioButtonList). I would like to add events to the control, but being new
to .NET I don't know where to start.
When the user changes selection by clicking another radio button, I would
like to do a postback and process the selected data.
 

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

Top