Please help with handling events in a tabstrip/multipage/user control environment

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
 
A

Ashok

Hi Aaron,

I don't know whether you solved this problem already or not. Here is how i
resolved it.

In the code behind keep the Multipage control declaration as the last one

protected Microsoft.Web.UI.WebControls.MultiPage WizardSteps;

In .aspx make sure that have your Multipage control related html info is
inside the start and ending tag of "form"

<form Id="TestForm>


==> All multipage related controls html data


</form> ending tag

Hope it works for you.

Ashok
 
A

Ashok

Hi Aron,

I forgot to mention few more things. Please read below too.

See in .aspx you have changed the name of the form. If you change the "name"
or "id" attribute of the .aspx file

for Example in .aspx file if you changed from

<form id="Form2" method="post" runat="server">


to


<form id="Wizard_InstallDeviceToAIMS_Disp_AssetsList" method="post"
runat="server">

then all the designer related events will be lost and you have to recreate
them in the


private void InitializeComponent()
{

}

of your multipage form.

This is another reason why your events don't fire in the multipage view
controls.


Thanks
Ashok Thota
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top