This is a migrated thread and some comments may be shown as answers.

dynamic step content addhandler problem

3 Answers 199 Views
Wizard
This is a migrated thread and some comments may be shown as answers.
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Fit2Page asked on 17 Aug 2016, 10:36 AM

Hi,

 

I have set up a small testpage to show my problem: When i Click on [Generate wizardsteps] the steps are created and [Next step] is working. When I click the [Generate wizardsteps] button again the steps are re-created, but I have to hit a [Next step] button twice in order to go to a next step. What could cause this behavior?

 

Here is my page code:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test2.aspx.vb" Inherits="test2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    

            <telerik:RadScriptManager runat="server"></telerik:RadScriptManager>


         <telerik:RadButton RenderMode="Lightweight" runat="server" ID="RadButton1" Text="Generate wizardsteps" OnClick="RadButton1_Click"></telerik:RadButton>


        <telerik:RadWizard DisplayNavigationButtons="false" OnWizardStepCreated="RadWizard1_WizardStepCreated" RenderMode="Lightweight" runat="server" ID="RadWizard1" Height="360px">
          
        </telerik:RadWizard>

    </div>
    </form>
</body>
</html>

and this is the code-behind:

Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Telerik.Web.UI

Partial Public Class test2
    Inherits System.Web.UI.Page

    Protected Sub RadButton1_Click(sender As Object, e As EventArgs)

        RadWizard1.WizardSteps.Clear()

        For i As Integer = 0 To 4
            Dim [step] As New RadWizardStep()
            [step].ID = "Step " + (i + 1).ToString()
            RadWizard1.WizardSteps.Add([step])
        Next
        Dim completeStep As New RadWizardStep()
        completeStep.ID = "Complete"
        RadWizard1.WizardSteps.Add(completeStep)

        RadWizard1.ActiveStepIndex = RadWizard1.WizardSteps(0).Index

    End Sub


    Protected Sub RadWizard1_WizardStepCreated(sender As Object, e As WizardStepCreatedEventArgs)

        Dim lc As New RadButton()
        lc.Text = "Next step"
        AddHandler lc.Command, AddressOf RadButton2_Click

        e.RadWizardStep.Controls.Add(lc)

    End Sub

    Protected Sub RadButton2_Click(sender As Object, e As EventArgs)
        Dim [step] As RadWizardStep = DirectCast(DirectCast(sender, RadButton).Parent, RadWizardStep)
        RadWizard1.ActiveStepIndex = RadWizard1.WizardSteps([step].Index).Index + 1
    End Sub

End Class

 

I really hope you can find something.

This is an excerpt from an important project.

 

Thanks, Marc

3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 22 Aug 2016, 10:14 AM
Hello Marc,

In scenarios, in which the Wizard steps are created dynamically and you don't want to use the default Next button,  we recommend  instead of navigating on the server to navigate on the client. Using your code here's an example that shows how this can be done in the button's OnClientButton2Clicked client-side handler:

Protected Sub RadWizard1_WizardStepCreated(sender As Object, e As WizardStepCreatedEventArgs)
 
    Dim lc As New RadButton()
    lc.Text = "Next step"
    lc.OnClientClicked = "OnClientButton2Clicked"
    AddHandler lc.Click, AddressOf RadButton2_Click
 
    e.RadWizardStep.Controls.Add(lc)
 
End Sub
 
Protected Sub RadButton2_Click(sender As Object, e As EventArgs)
    'Dim [step] As RadWizardStep = DirectCast(DirectCast(sender, RadButton).Parent, RadWizardStep)
    'RadWizard1.ActiveStepIndex = RadWizard1.WizardSteps([step].Index).Index + 1
End Sub

function OnClientButton2Clicked(sender, args) {
    var wizard = $find("<%= RadWizard1.ClientID%>");
    var steps = wizard.get_wizardSteps();
    var index = wizard.get_activeIndex();
    if ((index + 1) <= steps.get_count() - 1) {
        wizard.set_activeIndex(index + 1);
    }
}


Regards,
Ivan Danchev
Telerik by Progress
0
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
answered on 22 Aug 2016, 10:20 AM

Hi Ivan,

The choices on the next tab are depending on the choice made on the current tab.

With your solution that would mean that I have to load the choices rather on the client instead with server side code.

What would you recommend as a datasource for such a set-up?

Do you have sample code available for that?

Regards, Marc

 

0
Ivan Danchev
Telerik team
answered on 24 Aug 2016, 04:55 PM
Hi Marc,

I am not sure how the steps changing is related to loading their content. Could you elaborate more on why a different method of loading would be required, because moving the steps changing logic to the client does not prevent the server-side events from firing: RadWizard1_WizardStepCreated and RadButton2_Click still fire. And in RadButton2_Click you can still get the active step: RadWizard1.ActiveStepIndex. The same information is available on the client through calling the correct client-side method:
function OnClientButton2Clicked(sender, args) {
    var wizard = $find("<%= RadWizard1.ClientID%>");
    var steps = wizard.get_wizardSteps();
    var index = wizard.get_activeIndex();
    var nextStep = wizard.get_wizardStepByIndex(index + 1);
    var nextStepTitle = nextStep.get_title();
 
    if ((index + 1) <= steps.get_count() - 1) {
        wizard.set_activeIndex(index + 1);
    }
}

For example highlighted in yellow is how you can get information about the next step (the one with index equal to the current step's index + 1). Thus based on the data about the current or next or previous steps you can chose which step to navigate to. 

Regards,
Ivan Danchev
Telerik by Progress
Tags
Wizard
Asked by
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Ivan Danchev
Telerik team
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or