.NET Framework Developer Center >
.NET Development Forums
>
Common Language Runtime
>
Web Page Add Event Handler for Control
Web Page Add Event Handler for Control
- I have a licensed control that requires an event handler for InitializeDataSource. The vendor is Infragostics. I am in the process of rewritting my web application from VB to C#.
As a VB application, the following declaration for the event worked well.
Private Sub cmbSrchAdmnCont_InitializeDataSource(ByVal sender As Object, ByVal e As Infragistics.WebUI.WebCombo.WebComboEventArgs) Handles cmbSrchAdmnCont.InitializeDataSource
In the C# re-write, I have done the following in thecode file for the page:
Added override for OnInit:
protected override void OnInit(EventArgs e)
{
// I have ested this with the Initialize call first also
base.OnInit(e);
InitializeComponent();
}
Added the following method:
private void InitializeComponent()
{
// Add the event handlers for Infragistics Combo boxes
this.cmbSrchAdmnCont.InitializeDataSource += new Infragistics.WebUI.WebCombo.InitializeDataSourceEventHandler(this.cmbSrchAdmnCont_InitializeDataSource);
}
These are executed and verified by setting breakpoints. However, the event handler is never called in the C# version.
Is this the correct method for adding and registering event handlers for controls in a C# based .Net page?
Thanks in advance for any assistance towards a resolution.
Norm
Answers
- Hello Jialiang,
The new cmbSrchAdminContact is dclared in the ...Designer.cs file for the page.
I did not modify the Designer.cs because I thought that VS would completely re-write that file if any controls were added or removed from the page layout.
After I posted my original request, I did find a question on this same issue that was addressed by the licensee Infragistics. While they dropped the visibility to the event in the IDE for their Combo Box (and Grid) control, it still exists in their implementation. The solution was to add a tag to the HTML for the control for oninitializedatasource="<event handlername>"
Thanks for your thoughts on this. I will try your suggestion aanyway as I prefer staying away from having to write HTML if possible.
Norm Derrick- Marked As Answer byJialiang Ge [MSFT]MSFT, ModeratorWednesday, November 18, 2009 10:58 AM
All Replies
- Hello
Where do you "new" the cmbSrchAdmnCont object? Could you please register the event handler immediately after you new the object?
Please also check whether the cmbSrchAdmnCont in C# is identical the object in VB. Some missing set of properties may cause the problem.
Last but not least, please make sure that your cmbSrchAdmnCont was not disposed or GC-ed before the event is supposed to be fired.
Regards,
Jialiang Ge
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Hello Jialiang,
The new cmbSrchAdminContact is dclared in the ...Designer.cs file for the page.
I did not modify the Designer.cs because I thought that VS would completely re-write that file if any controls were added or removed from the page layout.
After I posted my original request, I did find a question on this same issue that was addressed by the licensee Infragistics. While they dropped the visibility to the event in the IDE for their Combo Box (and Grid) control, it still exists in their implementation. The solution was to add a tag to the HTML for the control for oninitializedatasource="<event handlername>"
Thanks for your thoughts on this. I will try your suggestion aanyway as I prefer staying away from having to write HTML if possible.
Norm Derrick- Marked As Answer byJialiang Ge [MSFT]MSFT, ModeratorWednesday, November 18, 2009 10:58 AM
- Hello Norm
There must be reasons for dropping the event. The workaround, oninitializedatasource="<event handlername>", may not be safe if the control is updated in future. I suggest that you contact the owner of the control and ask for their official suggestions.
If you have any other questions, please feel free to post here.
Regards,
Jialiang Ge
MSDN Subscriber Support in Forum
If you have any feedback of our support, please contact msdnmg@microsoft.com.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.


