A
Aaron
I cannot get an event to fire within my multipage/usercontrol environment.
I have been reading O'Reilly's "Programming ASP.NET 2nd Edition" and found
some information regarding handling events in user controls. Here is what I
have done...
I have dragged a button to my user control, SearchFields, and added a
handler:
Private Sub btnSubmitSearchPrefs_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnSubmitSearchPrefs.Click
RaiseEvent ButtonClick(sender, e)
End Sub
I have also added the event in the class definition of my user control:
Public Event ButtonClick(ByVal sender As Object, ByVal e As EventArgs)
In the aspx file, I have added a withevents clause for the usercontrol:
Protected WithEvents SearchFields As SearchFields
I also added a handler in the aspx file for the event which SHOULD be raised
from the UC:
Sub SaveSearchFieldsBtnClickEvent(ByVal sender As Object, ByVal e As
EventArgs)Handles SearchFields.ButtonClick 'Searchfields is the UC and
ButtonClick is the event in the UC
MessageBox.MessageBox.MsgBox("Click")
End Sub
So everything looks wired up correctly. (but must not be)
When the UC's btnSubmitSearchPrefs is clicked, it should raise an event,
ButtonClick, which should be handled on the aspx code-behind with the Sub,
SaveSearchFieldsBtnClickEvent.
I am still unable to hit the breakpoint.
Some additional information:
When I load the application for debugging here is what happens.
I click on the preferences tab which shows my pageview correctly. There is
nothing but a label and a dropdown list. When I select "Search" from the
dd, the page_load event fires from the user control. Here is that code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Then, after that sub finishes, PrefConfigSelect is called from the
code-behind of my aspx page. Here is that code:
Private Sub PrefConfigSelect(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ddSelectPrefArea.SelectedIndexChanged
Dim DDSelection As String
DDSelection = ddSelectPrefArea.SelectedItem.Value.ToString
'Check which dropdown selection was made and act accordingly
Select Case DDSelection
Case "Search"
Dim SFP As SearchFields = LoadControl("SearchFields.ascx")
pnlSearchPrefs.Controls.Add(SFP)
Case "Entry"
MessageBox.MessageBox.MsgBox("Entry")
Case "Edit"
MessageBox.MessageBox.MsgBox("Edit")
Case "Jobs"
MessageBox.MessageBox.MsgBox("Jobs")
Case "Companies"
MessageBox.MessageBox.MsgBox("Companies")
Case "Schedule"
MessageBox.MessageBox.MsgBox("Schedule")
Case "Research"
MessageBox.MessageBox.MsgBox("Research")
Case "Reports"
MessageBox.MessageBox.MsgBox("Reports")
End Select
End Sub
The user control is added to the panel and I see the checkboxes and submit
button.
When I click the submit button, a postback appears to occur, but no
messagebox is displayed and I cannot hit the breakpoint.
Why can I not hit the breakpoint I have set on the UC at
btnSubmitSearchPrefs_Click?
Does anyone handle events from their user controls and if so, am I going
about this correctly?
I would very much appreciate any advice or insight.
Thank you,
Aaron
I have been reading O'Reilly's "Programming ASP.NET 2nd Edition" and found
some information regarding handling events in user controls. Here is what I
have done...
I have dragged a button to my user control, SearchFields, and added a
handler:
Private Sub btnSubmitSearchPrefs_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnSubmitSearchPrefs.Click
RaiseEvent ButtonClick(sender, e)
End Sub
I have also added the event in the class definition of my user control:
Public Event ButtonClick(ByVal sender As Object, ByVal e As EventArgs)
In the aspx file, I have added a withevents clause for the usercontrol:
Protected WithEvents SearchFields As SearchFields
I also added a handler in the aspx file for the event which SHOULD be raised
from the UC:
Sub SaveSearchFieldsBtnClickEvent(ByVal sender As Object, ByVal e As
EventArgs)Handles SearchFields.ButtonClick 'Searchfields is the UC and
ButtonClick is the event in the UC
MessageBox.MessageBox.MsgBox("Click")
End Sub
So everything looks wired up correctly. (but must not be)
When the UC's btnSubmitSearchPrefs is clicked, it should raise an event,
ButtonClick, which should be handled on the aspx code-behind with the Sub,
SaveSearchFieldsBtnClickEvent.
I am still unable to hit the breakpoint.
Some additional information:
When I load the application for debugging here is what happens.
I click on the preferences tab which shows my pageview correctly. There is
nothing but a label and a dropdown list. When I select "Search" from the
dd, the page_load event fires from the user control. Here is that code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Then, after that sub finishes, PrefConfigSelect is called from the
code-behind of my aspx page. Here is that code:
Private Sub PrefConfigSelect(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ddSelectPrefArea.SelectedIndexChanged
Dim DDSelection As String
DDSelection = ddSelectPrefArea.SelectedItem.Value.ToString
'Check which dropdown selection was made and act accordingly
Select Case DDSelection
Case "Search"
Dim SFP As SearchFields = LoadControl("SearchFields.ascx")
pnlSearchPrefs.Controls.Add(SFP)
Case "Entry"
MessageBox.MessageBox.MsgBox("Entry")
Case "Edit"
MessageBox.MessageBox.MsgBox("Edit")
Case "Jobs"
MessageBox.MessageBox.MsgBox("Jobs")
Case "Companies"
MessageBox.MessageBox.MsgBox("Companies")
Case "Schedule"
MessageBox.MessageBox.MsgBox("Schedule")
Case "Research"
MessageBox.MessageBox.MsgBox("Research")
Case "Reports"
MessageBox.MessageBox.MsgBox("Reports")
End Select
End Sub
The user control is added to the panel and I see the checkboxes and submit
button.
When I click the submit button, a postback appears to occur, but no
messagebox is displayed and I cannot hit the breakpoint.
Why can I not hit the breakpoint I have set on the UC at
btnSubmitSearchPrefs_Click?
Does anyone handle events from their user controls and if so, am I going
about this correctly?
I would very much appreciate any advice or insight.
Thank you,
Aaron