Create steps depending on user input in first step

2 posts, 0 answers
  1. Al
    Al avatar
    6 posts
    Member since:
    Nov 2012

    Posted 06 Dec 2015 Link to this post

    Hi! I am trying to create HelpDesk functionality using RadWizard to create new incident.

    On first step user selects incident category from RadComboBox (hardware problems, software etc)

    Then i dynamically create 2 new steps with a different markup depending on combobox selected value.

    Everything works fine until user goes back to first step and selects new RadComboBox value.

    Functionality allows to do such thing. And i have to delete next steps and create new ones with other markup.

    I found simple solution to disable RadComboBox, but it seems to be uncorrect solution. Can you help me?

    Here is my code

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Default" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
         
            <asp:ScriptManager runat="server" />
            <div>
     
                <script type="text/javascript">
                </script>
                <telerik:RadWizard runat="server" ID="RadWizard1" Height="360px"
                     OnNextButtonClick="RadWizard1_NextButtonClick" OnWizardStepCreated="RadWizard1_WizardStepCreated" DisplayCancelButton="True">
                    <WizardSteps>
                        <telerik:RadWizardStep ID="RadWizardStep1" runat="server" Title="Book Group Vacation" StepType="Start" DisplayCancelButton="True" >
                            <telerik:RadComboBox ID="RadComboBox1" Runat="server" AutoPostBack="False">
                                <Items>
                                    <telerik:RadComboBoxItem runat="server" Text="1" Value="1" />
                                    <telerik:RadComboBoxItem runat="server" Text="2" Value="2" />
                                    <telerik:RadComboBoxItem runat="server" Text="3" Value="3" />
                                </Items>
                            </telerik:RadComboBox>
                            <br/>
                            <label>ComboBox Value Is </label><span id="CB" runat="server"></span>
                             
                        </telerik:RadWizardStep>
                    </WizardSteps>
                </telerik:RadWizard>
            </div>
        </form>
    </body>
    </html>
    And code-behind

    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    using System.Data;
    using System.Configuration;
    using System.Web.Security;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Telerik.Web.UI;
     
    public partial class Default : System.Web.UI.Page
     
    {
        private static bool _stepCreated = false;
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack && !_stepCreated)
            {
                CB.InnerText = RadComboBox1.SelectedValue.ToString();
                RadWizardStep step2 = new RadWizardStep();
                step2.ID = "Second";
     
                RadWizard1.WizardSteps.Add(step2);
                RadWizardStep step3 = new RadWizardStep();
                step3.ID = "Third";
     
                RadWizard1.WizardSteps.Add(step3);
     
                RadWizardStep completeStep = new RadWizardStep();
                completeStep.ID = "Complete";
                RadWizard1.WizardSteps.Add(completeStep);
                _stepCreated = true;
                RadComboBox1.Enabled = false;
                RadWizard1.ActiveStepIndex = RadWizard1.WizardSteps[1].Index;
            }
            
        }
        
     
        protected void rbRemove_Click(object sender, EventArgs e)
        {
            RadWizardStep step = ((RadWizardStep)((RadButton)sender).Parent);
            RadWizard1.WizardSteps.Remove(step);
            RadWizard1.ActiveStepIndex = 0;
        }
     
        protected void RadWizard1_WizardStepCreated(object sender, Telerik.Web.UI.WizardStepCreatedEventArgs e)
        {
            if (e.RadWizardStep.ID == "Complete")
            {
                e.RadWizardStep.StepType = RadWizardStepType.Complete;
                Label label = new Label();
                label.Text = "Registration succeeded!";
                e.RadWizardStep.Controls.Add(label);
            }
            else
            {
                e.RadWizardStep.CssClass = "passenger";
                string[] labelTitle = new string[] { "First Name:", "Second Name:", "Third Name:" };
     
                for (int i = 0; i < labelTitle.Length; i++)
                {
                    RadTextBox rcbFirstName = new RadTextBox();
                    rcbFirstName.LabelWidth = Unit.Pixel(150);
                    rcbFirstName.Width = Unit.Pixel(500);
                    rcbFirstName.Label = labelTitle[i];
                    e.RadWizardStep.Controls.Add(rcbFirstName);
                    e.RadWizardStep.Controls.Add(new Literal() { Text = "<br />" });
                }
                RadTextBox rcbVal = new RadTextBox();
                rcbVal.LabelWidth = Unit.Pixel(150);
                rcbVal.Width = Unit.Pixel(500);
                rcbVal.Label = "ComboBoxValue";
                rcbVal.Text = RadComboBox1.SelectedValue.ToString();
                e.RadWizardStep.Controls.Add(rcbVal);
                e.RadWizardStep.Controls.Add(new Literal() { Text = "<br />" });
     
                RadButton rbRemove = new RadButton();
                rbRemove.Text = "Remove Person";
                rbRemove.Click += rbRemove_Click;
                e.RadWizardStep.Controls.Add(rbRemove);
            }
        }
        protected void RadWizard1_NextButtonClick(object sender, WizardEventArgs e)
        {
            RadWizard wiz = (RadWizard)sender;
            
            Response.Write(wiz.WizardSteps[e.CurrentStepIndex].ID);
            Response.Write(wiz.WizardSteps[e.NextStepIndex].ID);
        }
     
        
     
    }

  2. Plamen
    Admin
    Plamen avatar
    2790 posts

    Posted 09 Dec 2015 Link to this post

    Hello,

    Disabling RadComboBox seems like a legit solution. You may also check if the steps are already added to the control before adding them so you don't duplicate them.

    Regards,
    Plamen
    Telerik
Back to Top