dynamic step content addhandler problem

4 posts, 0 answers
  1. Fit2Page
    Fit2Page avatar
    345 posts
    Member since:
    Feb 2007

    Posted 17 Aug Link to this post

    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

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 22 Aug Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Fit2Page
    Fit2Page avatar
    345 posts
    Member since:
    Feb 2007

    Posted 22 Aug in reply to Ivan Danchev Link to this post

    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

     

  5. Ivan Danchev
    Admin
    Ivan Danchev avatar
    829 posts

    Posted 24 Aug Link to this post

    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
Back to Top