NullReferenceException Error - Wizard Template

Discussion in 'ASP .Net Web Controls' started by Morris Neuman, Jan 25, 2010.

  1. Hi,
    I have a web page with a master page and a contents page. On the contents
    page I have a wizard as defined below:
    <asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="1"
    DisplayCancelButton="True" Height="85px" Width="647px"
    OnNextButtonClick="NextButtonClick_SkipStep"
    OnActiveStepChanged="OnActiveStepChanged_SaveCurrPrevIndex"

    CancelDestinationPageUrl="~/SystemAdminOnly/CMTables/OutcallSchedule/ManageOutcallSchedule-LoadNumbers.aspx"
    DisplaySideBar="False">
    <StepStyle HorizontalAlign="Left" VerticalAlign="Top" />
    <StartNavigationTemplate>
    <asp:Button ID="StartNextButton" runat="server"
    CommandName="MoveNext" Visible="false"
    Text="Next" />
    <asp:Button ID="CancelButton" runat="server"
    CausesValidation="False"
    CommandName="Cancel" Text="Cancel" />
    </StartNavigationTemplate>
    <WizardSteps>
    <asp:WizardStep runat="server" StepType="Start" title="Step 1">
    <code style="font-family: Verdana; font-size: 10pt; color:
    navy; ">Step1...</code>
    </asp:WizardStep>
    <asp:WizardStep runat="server" StepType="Start" title="Step 2">
    <code style="font-family: Verdana; font-size: 10pt; color: navy;
    ">Step2...</code>
    </asp:WizardStep>
    </asp:WizardSteps>
    <SideBarStyle VerticalAlign="Top" />
    <StepNavigationTemplate>
    <asp:Button ID="StepPreviousButton" runat="server"
    CausesValidation="False"
    CommandName="MovePrevious" Text="Previous" />
    <asp:Button ID="StepNextButton" runat="server"
    CommandName="MoveNext"
    Text="Next" Visible="false"/>
    <asp:Button ID="CancelButton" runat="server"
    CausesValidation="False"
    CommandName="Cancel" Text="Cancel" />
    </StepNavigationTemplate>
    </asp:Wizard>

    I also have a script defined to set display of the StepNextButton in the
    StepNavigationTemplate.
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    TextBox3.Text = "0";
    TextBox4.Text = "0";
    }
    }

    protected void OnActiveStepChanged_SaveCurrPrevIndex(object sender,
    EventArgs e)
    {
    if (IsPostBack)
    //NOT first time
    {
    TextBox3.Text = TextBox4.Text;
    TextBox4.Text = Wizard1.ActiveStepIndex.ToString();
    }

    if (Wizard1.ActiveStepIndex == 1)
    {
    Button btn =
    (Button)Wizard1.FindControl("StepNavigationTemplateContainerID$StepNextButton");
    btn.Visible = true;
    }

    if (Wizard1.ActiveStepIndex >1)
    {
    Button btn =
    (Button)Wizard1.FindControl("StepNavigationTemplateContainerID$StepNextButton");
    btn.Visible = false;
    }
    }

    When this page is activated, I get the following error:
    Exception Details: System.NullReferenceException: Object reference not set
    to an instance of an object.

    Source Error:
    Line 53: {
    Line 54: Button btn =
    (Button)Wizard1.FindControl("StepNavigationTemplateContainerID$StepNextButton");
    Line 55: btn.Visible = true;
    Line 56: }
    Line 57:

    Can you tell me why and what I need to change?

    --
    Thanks for your help.

    --
    Thanks
    Morris
    Morris Neuman, Jan 25, 2010
    #1
    1. Advertising

  2. Hi Morris,

    Based on the code you posted, you set Wizard's ActiveStepIndex to "1" When
    we request the page first time, and the control has not been initialized in
    OnActiveStepChanged event, so we receive the exception.

    In this case, you can find control and set its property in PageLoad event
    when page is requested first time.
    =================================================
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    TextBox3.Text = "0";
    TextBox4.Text = "0";

    //
    //TO DO: Find Control and set its property when page is
    requested first time
    //

    }

    }

    protected void OnActiveStepChanged_SaveCurrPrevIndex(object sender,
    EventArgs e)
    {
    if (IsPostBack)
    //NOT first time
    {
    TextBox3.Text = TextBox4.Text;
    TextBox4.Text = Wizard1.ActiveStepIndex.ToString();

    //
    //TO DO: Find Control and set its property when page is NOT
    requested first time.
    //
    if (Wizard1.ActiveStepIndex == 1)
    {
    Button btn =

    (Button)Wizard1.FindControl("StepNavigationTemplateContainerID$StepNextButto
    n");
    btn.Visible = true;
    }

    if (Wizard1.ActiveStepIndex > 1)
    {
    Button btn =

    (Button)Wizard1.FindControl("StepNavigationTemplateContainerID$StepNextButto
    n");
    btn.Visible = false;
    }

    }
    }

    =================================================

    I look forward to receiving your test results.


    --

    Best Regards,
    Thomas Sun

    Microsoft Online Partner Support

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.

    With newsgroups, MSDN subscribers enjoy unlimited, free support as opposed
    to the limited number of phone-based technical support incidents. Complex
    issues or server-down situations are not recommended for the newsgroups.
    Issues of this nature are best handled working with a Microsoft Support
    Engineer using one of your phone-based incidents.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thomas Sun [MSFT], Jan 26, 2010
    #2
    1. Advertising

  3. It worked.
    --
    Thanks for your help.
    Morris


    "Thomas Sun [MSFT]" wrote:

    > Hi Morris,
    >
    > Based on the code you posted, you set Wizard's ActiveStepIndex to "1" When
    > we request the page first time, and the control has not been initialized in
    > OnActiveStepChanged event, so we receive the exception.
    >
    > In this case, you can find control and set its property in PageLoad event
    > when page is requested first time.
    > =================================================
    > protected void Page_Load(object sender, EventArgs e)
    > {
    > if (!IsPostBack)
    > {
    > TextBox3.Text = "0";
    > TextBox4.Text = "0";
    >
    > //
    > //TO DO: Find Control and set its property when page is
    > requested first time
    > //
    >
    > }
    >
    > }
    >
    > protected void OnActiveStepChanged_SaveCurrPrevIndex(object sender,
    > EventArgs e)
    > {
    > if (IsPostBack)
    > //NOT first time
    > {
    > TextBox3.Text = TextBox4.Text;
    > TextBox4.Text = Wizard1.ActiveStepIndex.ToString();
    >
    > //
    > //TO DO: Find Control and set its property when page is NOT
    > requested first time.
    > //
    > if (Wizard1.ActiveStepIndex == 1)
    > {
    > Button btn =
    >
    > (Button)Wizard1.FindControl("StepNavigationTemplateContainerID$StepNextButto
    > n");
    > btn.Visible = true;
    > }
    >
    > if (Wizard1.ActiveStepIndex > 1)
    > {
    > Button btn =
    >
    > (Button)Wizard1.FindControl("StepNavigationTemplateContainerID$StepNextButto
    > n");
    > btn.Visible = false;
    > }
    >
    > }
    > }
    >
    > =================================================
    >
    > I look forward to receiving your test results.
    >
    >
    > --
    >
    > Best Regards,
    > Thomas Sun
    >
    > Microsoft Online Partner Support
    >
    > ==================================================
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    >
    > With newsgroups, MSDN subscribers enjoy unlimited, free support as opposed
    > to the limited number of phone-based technical support incidents. Complex
    > issues or server-down situations are not recommended for the newsgroups.
    > Issues of this nature are best handled working with a Microsoft Support
    > Engineer using one of your phone-based incidents.
    > ==================================================
    >
    > This posting is provided "AS IS" with no warranties, and confers no rights.
    >
    > .
    >
    Morris Neuman, Jan 26, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Manny
    Replies:
    1
    Views:
    439
    Lau Lei Cheong
    Aug 2, 2004
  2. =?Utf-8?B?UGF0cmljay5PLklnZQ==?=

    Whats the error:- System.NullReferenceException:

    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=, Oct 31, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    4,588
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Nov 1, 2004
  3. Replies:
    4
    Views:
    933
  4. Replies:
    0
    Views:
    594
  5. Andy B
    Replies:
    0
    Views:
    431
    Andy B
    Apr 19, 2008
Loading...

Share This Page