Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cancel step if validation fails in asp.net wizard

Tags:

c#

asp.net

I am using asp.net wizard in my project which is new to me. I have validations in one of the steps in my wizard. If the validation fails i should not allow the user to go to next step. And i am using a asp.net button which navigate between the steps in wizard. I would really appreciate if anyone could help me.

like image 213
Praveen Mitta Avatar asked Dec 16 '22 01:12

Praveen Mitta


2 Answers

You could try canceling the Wizard's SideBarButtonClick and NextButtonClick events:

 protected void Wizard1_SideBarButtonClick(object sender, WizardNavigationEventArgs e)
  {
    e.Cancel = !ValidateWizardStep(e.NextStepIndex);
  }

  protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
  {
    e.Cancel = !ValidateWizardStep(e.NextStepIndex);
  }
like image 158
Ulises Avatar answered Jan 02 '23 08:01

Ulises


I tweaked the code a little bit sent by Ulises and made it work.

  1. I have added onNextButtonClick property for wizard

    <asp:Wizard ID="wizClaimInfo" runat="server" CssClass="wizard" DisplayCancelButton="True" ActiveStepIndex="0" OnNextButtonClick="wizClaimInfo_NextButtonClick">
    
  2. In the codebehind added following event

    protected void wizClaimInfo_NextButtonClick(object sender, WizardNavigationEventArgs e) {
    
            if (!IsValid)
            {
                e.Cancel = true;
            }
    
        return;
    }
    

and also followed instruction given in below link.

http://forums.asp.net/t/1014412.aspx/2/10

I hope this will help someone in the future, because i spent almost 2 days trying to figure it out. And special thanks to Mr.Ulises.

like image 22
Praveen Mitta Avatar answered Jan 02 '23 09:01

Praveen Mitta