Answered by:
Custom server control events questions

Question
-
User-1439923671 posted
I need a custom server control which contains one TextBox and one RadioButtonList. I need to define a OnValueChanged event on custom server control which can capture the TextChanged event of TextBox OR SelectedIndexChanged event of RadioButtonListj, so that I can get the Text value of TextBox OR SelectedIndex value of RadioButtonList. Then I can use that value to continue more functions in OnValueChanged event. Can anybody show me how to implement that? Some examples or codes would be greatly appreciated!
Friday, July 25, 2008 1:29 AM
Answers
-
User-916962509 posted
You need to create a custom event which you can raise. You can then handle your custom event whenever it gets fired.
For example, create a custom event "SelectedValueChanged".
Then, create some handlers in your control to handle the TextChanged of the textbox and SelectedValueChanged of the RadiobuttonList. Make both of these handlers raise your custom event.
Something like this- it compiles but I have not tested it.
1 Public Class TestControl 2 ' All rendering, etc, omitted for clarity. 3 4 Private _TextBox As TextBox 5 Private _RadioButtonList As RadioButtonList 6 7 Public Event SelectedValueChanged(ByVal sender As Object, ByVal e As EventArgs, ByVal NewValue As String) 8 9 10 Private Sub TextboxTextChangedHandler(ByVal sender As Object, ByVal e As EventArgs) 11 RaiseEvent SelectedValueChanged(sender, e, _TextBox.Text) 12 End Sub 13 14 Private Sub RadiobuttonListChangedHandler(ByVal sender As Object, ByVal e As EventArgs) 15 RaiseEvent SelectedValueChanged(sender, e, _RadioButtonList.SelectedIndex.ToString()) 16 End Sub 17 18 19 Public Sub New() 20 ' Wire up handlers 21 AddHandler _TextBox.TextChanged, AddressOf TextboxTextChangedHandler 22 AddHandler _RadioButtonList.SelectedIndexChanged, AddressOf RadiobuttonListChangedHandler 23 End Sub 24 25 26 27 End Class
Let me know how you go on.
bgs264
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 29, 2008 7:55 AM
All replies
-
User1037547548 posted
Can anybody show me how to implement that? Some examples or codes would be greatly appreciated!I created TellAFriend Custom Control. This helps you. Visit MyBlog
Regard
Khan
Friday, July 25, 2008 2:44 AM -
User-916962509 posted
You need to create a custom event which you can raise. You can then handle your custom event whenever it gets fired.
For example, create a custom event "SelectedValueChanged".
Then, create some handlers in your control to handle the TextChanged of the textbox and SelectedValueChanged of the RadiobuttonList. Make both of these handlers raise your custom event.
Something like this- it compiles but I have not tested it.
1 Public Class TestControl 2 ' All rendering, etc, omitted for clarity. 3 4 Private _TextBox As TextBox 5 Private _RadioButtonList As RadioButtonList 6 7 Public Event SelectedValueChanged(ByVal sender As Object, ByVal e As EventArgs, ByVal NewValue As String) 8 9 10 Private Sub TextboxTextChangedHandler(ByVal sender As Object, ByVal e As EventArgs) 11 RaiseEvent SelectedValueChanged(sender, e, _TextBox.Text) 12 End Sub 13 14 Private Sub RadiobuttonListChangedHandler(ByVal sender As Object, ByVal e As EventArgs) 15 RaiseEvent SelectedValueChanged(sender, e, _RadioButtonList.SelectedIndex.ToString()) 16 End Sub 17 18 19 Public Sub New() 20 ' Wire up handlers 21 AddHandler _TextBox.TextChanged, AddressOf TextboxTextChangedHandler 22 AddHandler _RadioButtonList.SelectedIndexChanged, AddressOf RadiobuttonListChangedHandler 23 End Sub 24 25 26 27 End Class
Let me know how you go on.
bgs264
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 29, 2008 7:55 AM