Changing text of Next, Previous buttons or hiding them in a Wizard control

Here is the problem : You have <asp:Wizard ID=”Wizard1″ runat=”server”/> and depending on some conditions you want to do all or one  of the following :

  • Change the Text of Previous or Next buttons
  • Hide or disable Previous or Next buttons

But the problem is that no matter what you do, you can’t get the handle to the button controls in the Wizard. You probably tried doing Wizard1.ActiveStep.FindControl(“StepNextButton”) or Wizard1.FindControl(“StepNextButton”), but you always get null.

This is what worked for me :

  • First go to design mode and Create a StepNavigation Template.
  • Go to ASPX source, you will see something like this :
  • <stepnavigationtemplate> <asp:Button ID=”StepPreviousButton” runat=”server”  CommandName=”MovePrevious” Text=”Previous” /> <asp:Button ID=”StepNextButton” runat=”server”  CommandName=”MoveNext” Text=”Next” OnInit=”StepNextButton_Init”/></stepnavigationtemplate>
  • If you notice, I have added an OnInit to the StepNextButton, to catch the Init even of the button.
  • Switch back to your Codebehind.
    • Partial Class Home Inherits System.Web.UI.Page
    • Dim m_NextButton As Button ‘Declare a class level variable to hold reference to the Next button
    • ‘Add the event handler and store the value of Sender in the class variable. Now, you can use m_NextButton to reference the button
  • Protected Sub StepNextButton_Init(ByVal Sender As Object, ByVal e As EventArgs)

    m_NextButton = Sender

    End Sub

Advertisements

7 thoughts on “Changing text of Next, Previous buttons or hiding them in a Wizard control

  1. I read through so many pages of crap trying to figure out how to do this… nothing beats the simplicity of your post. Thanks! -pat.c

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s