• 0

Populate DropDownList in TemplatedStepWizard


Question

Hi - I'm having a strange problem. I'm trying to populate a dropdown list, held in "Step 2" of a asp:Wizard. The code is shown below. But the script ditches out at the items.add line. Any ideas what might be wrong?

<asp:Wizard ID="SignUpWizard"
                            runat="server"
                            onfinishbuttonclick="OnFinishButtonClick"
                            onactivestepchanged="OnActiveStepChanged"
                            DisplaySideBar="false" EnableTheming="True">
                            <WizardSteps>
                                <asp:TemplatedWizardStep ID="Intro" runat="server">
                                    <ContentTemplate>blah</ContentTemplate>
				</asp:TemplatedWizardStep>
				<asp:TemplatedWizardStep ID="Step2" runat="server">
					<asp:Dropdownlist ID="DoBMonth" runat="server" />
				</asp:TemplatedWizardStep>

Code behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load    

End Sub    

Protected Sub OnFinishButtonClick(ByVal sender As [Object], ByVal e As WizardNavigationEventArgs)        
  Response.Redirect("http://www.bbc.co.uk")    

End Sub    

Protected Sub OnGoBackButtonClick(ByVal sender As Object, ByVal e As EventArgs)    

End Sub    

Protected Sub OnActiveStepChanged(ByVal sender As Object, ByVal e As EventArgs)        
  If SignUpWizard.ActiveStep.ID = "Step2" Then            
    Dim theMonth As New DropDownList            
    theMonth = SignUpWizard.FindControl("DoBMonth")            
    theMonth.Items.Add(New ListItem("January", "January"))				<<<<<<<<<<<<<<<<<<< crashes here
  End If    
End Sub

Edited by Antaris
Added code blocks
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

You are not casting "theMonth" to the appropriate type. The FindControl method returns instances of type: Control, you need to then do something like:

Dim theMonth As DropDownList = CType(SignUpWizard.FindControl("DoBMonth"), DropDownList)

It's been a while since I've done VB!

Link to comment
Share on other sites

  • 0

Thanks for the response Antaris. I've tried your suggestion, but I keep getting "NullReferenceException was unhandled by user code - object reference not set to an instance of an object." Any ideas?

Link to comment
Share on other sites

  • 0

If you're getting a NullReferenceException, it means it cannot resolve DoBMonth to an actual control. In your ASPX page, you aren't using ContentTemplate within Step 2's TemplateWizardStep, that could be the reason, try:

<asp:TemplatedWizardStep ID="Step2" runat="server">
  <ContentTemplate>
    <asp:Dropdownlist ID="DoBMonth" runat="server" />
  </ContentTemplate>
</asp:TemplatedWizardStep>

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.