Handeling Control Events from Web Form page

I am working with an existing C#.net project. I have created a control of radio buttons in a new .ascx page. I am placing that .ascx control on multiple pages throughout the site where the functionality is needed. The control is replacing existing radio buttons on various pages where there is code written for it. One of the pages that I have come across has some events tied to the radio buttons, that I cannot include in the new generic control, as it would not apply to all other areas.

With that all said... after placing the control on the page, is there a way to have the main form handle a selectindexchanged event from the control without that event firing when placing that control on other pages?
Michael KrumpeSolutions ArchitectAsked:
Who is Participating?
Rog DConnect With a Mentor Manager Inforamtion SystemsCommented:
No delegate needed.

I think the Public Event is like the delegate.  I am not sure as I have not used Delegates.

The above works though.

Give it a try with your control.

Rog DManager Inforamtion SystemsCommented:
Rog DManager Inforamtion SystemsCommented:
This link maybe more informative


As the one above seems to be more on Gridview events.

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Michael KrumpeSolutions ArchitectAuthor Commented:
I understand how to make a control,... the control is already made and functioning. I need to make a specific page that I put the control on to respond to one of the controls events in its own way.
Rog DManager Inforamtion SystemsCommented:
My fault, those articles only talked about user controls, I thought they also included event handling.

Here they discuss events...

Look at Adding Events: section in the middle of the page.

Rog DManager Inforamtion SystemsCommented:
Here is a real rough idea of what we do.. .. I just could not find it on the web....

This is not compiled code it is just a snipet from a parent and user control.

We use http://www.denisbauer.com/Default.aspx dynamiccontrolplaceholder control for our controls, but it is just a placeholder that allows some better handeling of events and viewstate on the controls on postback.

Anyway take a look at the code and hopefully the sample and the links above will help you out.

In the parent control
Page_Init sub
	AddHandler usercontrol.Item_saved, AddressOf listen_Item_saved
end sub
Private Sub listen_Item_Saved()
        Session("Item" & win_id) = Nothing
end Sub
End class
In the child control....
Partial Public Class userControl1
	Inherits userControl
	Public Event Item_Saved()
Private Sub btn_save_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_save.Click
        ' save the college to the database and raise an event for the page to respond to.
        If Page.IsValid Then
                RaiseEvent Item_saved()
            Catch ex As Exception
		throw ex
            End Try
        End If
    End Sub
end class

Open in new window

Michael KrumpeSolutions ArchitectAuthor Commented:
In this instance, do you create a delegate for the Event Handler?
Rog DManager Inforamtion SystemsCommented:
All Courses

From novice to tech pro — start learning today.