Michael Krumpe
asked on
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?
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?
This link maybe more informative
http://www.15seconds.com/issue/020319.htm
As the one above seems to be more on Gridview events.
Rog
http://www.15seconds.com/issue/020319.htm
As the one above seems to be more on Gridview events.
Rog
ASKER
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.
My fault, those articles only talked about user controls, I thought they also included event handling.
Here they discuss events...
http://www.eggheadcafe.com/articles/20050710.asp
Look at Adding Events: section in the middle of the page.
Here they discuss events...
http://www.eggheadcafe.com/articles/20050710.asp
Look at Adding Events: section in the middle of the page.
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.
Rog
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.
Rog
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
Try
RaiseEvent Item_saved()
Catch ex As Exception
throw ex
End Try
End If
End Sub
end class
ASKER
In this instance, do you create a delegate for the Event Handler?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Here is another sample code in C# too.
http://codebetter.com/blogs/brendan.tompkins/archive/2004/10/06/Easily-Raise-Events-From-ASP.NET-ASCX-User-Controls.aspx
Rog
http://codebetter.com/blogs/brendan.tompkins/archive/2004/10/06/Easily-Raise-Events-From-ASP.NET-ASCX-User-Controls.aspx
Rog
http://aspnet.4guysfromrolla.com/articles/051105-1.aspx
Rog