Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application i have a wizard control where i will get the steps in wizard after loading the application firstly i will get wizard 1 then if i click next button i will get wizard 2 with second question my requirement is i need to check if a radio button for first question is selected or not if user clicks next button with selecting first radio button then i need to show a msg that first question should be answered first on a condition without going to second question other wise if a radio button is selected for first question then there is no need of showing the message how can i do this


ASP.NET
<pre><asp:Wizard ID="Wizard1" runat="server" DisplaySideBar="false" onnextbuttonclick="Wizard1_NextButtonClick" onfinishbuttonclick="Wizard1_FinishButtonClick" >
           <WizardSteps>
               <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">
                <div class="content">
                <table>
                <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left;"></td></tr>
                    <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left;"></td></tr>
                    <tr><td style="width:136px; text-align:center; color:#C57808; font-weight:bold;">Q 01</td><td style="width:800px; text-align:left; padding-left:8px; font-weight:bold; font-size:18px; color:#C57808;">What will be the time now</td></tr>
                    <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left; padding-left:100px; font-size:17px; color:Green; font-family:@Gulim;">A. <asp:RadioButton ID="rb1A" GroupName="g1" runat="server" Text="Ans1" /> </td></tr>
                    <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left; padding-left:100px; font-size:17px; color:Green; font-family:@Gulim;">B. <asp:RadioButton ID="rb1B" GroupName="g1" runat="server" Text="Ans2" /> </td></tr>
                    <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left; padding-left:100px; font-size:17px; color:Green; font-family:@Gulim;">C. <asp:RadioButton ID="rb1C" GroupName="g1" runat="server" Text="Ans3" /> </td></tr>
                    <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left;"></td></tr>
                    <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left;"></td></tr>
                    <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left;"></td></tr>
                    <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left;">
                </table>
                </div>
               </asp:WizardStep>
               <asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2">
                   <div class="content">
                    <table style="width:936px; height:450px; border:1px solid black; vertical-align:top; font-family:Verdana; font-size:15px; ">                    
                        <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left;"></td></tr>
                        <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left;"></td></tr>
                        <tr><td style="width:136px; text-align:center; color:#C57808; font-weight:bold;">Q 02</td><td style="width:800px; text-align:left; padding-left:8px; font-weight:bold; font-size:18px; color:#C57808;">How should i complete this</td></tr>
                        <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left; padding-left:100px; font-size:17px; color:Green; font-family:@Gulim;">A. <asp:RadioButton ID="rb2A" GroupName="g2" runat="server" Text="Will I" /> </td></tr>
                        <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left; padding-left:100px; font-size:17px; color:Green; font-family:@Gulim;">B. <asp:RadioButton ID="rb2B" GroupName="g2" runat="server" Text="Do I" /> </td></tr>
                        <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left; padding-left:100px; font-size:17px; color:Green; font-family:@Gulim;">C. <asp:RadioButton ID="rb2C" GroupName="g2" runat="server" Text="Can i" /> </td></tr>
                        <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left;"></td></tr>
                        <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left;"></td></tr>
                        <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left;"></td></tr>
                        <tr><td style="width:136px; text-align:center"></td><td style="width:800px; text-align:left;"></td></tr>
                    </table>
                   </div>
               </asp:WizardStep>
          </WizardSteps>
           <HeaderTemplate>
               <ul id="wizHeader">
                   <asp:Repeater ID="SideBarList" runat="server">
                       <ItemTemplate>
                           <li><a class="<%# GetClassForWizardStep(Container.DataItem) %>" title="<%#Eval("Name")%>">
                               <%# Eval("Name")%></a> </li>
                       </ItemTemplate>
                   </asp:Repeater>
               </ul>
           </HeaderTemplate>
       </asp:Wizard>



protected void Wizard1_PreRender(object sender, EventArgs e)
{
Repeater SideBarList = Wizard1.FindControl("HeaderContainer").FindControl("SideBarList") as Repeater;
SideBarList.DataSource = Wizard1.WizardSteps;
SideBarList.DataBind();
}
protected string GetClassForWizardStep(object wizardStep)
{
WizardStep step = wizardStep as WizardStep;

if (step == null)
{
return "";
}
int stepIndex = Wizard1.WizardSteps.IndexOf(step);

if (stepIndex < Wizard1.ActiveStepIndex)
{
return "prevStep";
}
else if (stepIndex > Wizard1.ActiveStepIndex)
{
return "nextStep";
}
else
{
return "currentStep";
}
}
protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
}

What I have tried:

i tried by using if else condition to validate whether radio buttons are checked or not when we click next button but if user does not select any radio button i am returning there it self but still it is executing Wizard1_PreRender and GetClassForWizardStep methods
Posted
Updated 1-Apr-18 23:44pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900