ASP Buttons not working after changing ActiveViewIndex

Go To StackoverFlow.com

2

I'm using MultiView to build a multi step form. The next button works on the first step (ViewOne) but then both the next and back buttons do nothing at the next step (ViewTwo).

I don't know if there is any clue in the below code or you need to see more?...

 <asp:MultiView ID="MultiView2" runat="server" ActiveViewIndex="0">
 <asp:View ID="ViewOne" runat="server">
 </asp:View>
 <asp:View ID="ViewTwo" runat="server">
 </asp:View>
 </asp:MultiView>
 <asp:ImageButton ID="btnBack" runat="server" ImageUrl="/assets/back_button.jpg"  OnClick="btnBack_Click" /> 
 <asp:ImageButton ID="btnNext" runat="server" ImageUrl="/assets/next_button.gif" OnClick="btnNext_Click" />
 <asp:ImageButton ID="btnSubmit" runat="server" ImageUrl="/assets/submit_button.gif" OnClick="btnSend_Click" />

Code behind....

protected void btnBack_Click(object sender, EventArgs e)
    {
        MultiView2.ActiveViewIndex--;
    }

    protected void btnNext_Click(object sender, EventArgs e)
    {
        MultiView2.ActiveViewIndex++;
    }

    protected void btnSend_Click(object sender, EventArgs e)
    {
        OnSubmitClicked(e);
    }

Ok more code...

protected override void OnLoad(EventArgs e)
{
        base.OnLoad(e);
     PopulateSomeField();
    }

protected override void OnPreRender(EventArgs e)
    {
        btnBack.Visible = MultiView2.ActiveViewIndex > 0;
        btnNext.Visible = MultiView2.ActiveViewIndex < MultiView2.Views.Count - 1;
        btnSubmit.Visible = MultiView2.ActiveViewIndex == MultiView2.Views.Count - 1;
        base.OnPreRender(e);
    }
2012-04-05 14:38
by Brian


2

There's no error there. It works just fine for me.

Test2.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test2.aspx.cs" Inherits="test2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:MultiView ID="MultiView2" runat="server" ActiveViewIndex="0">
         <asp:View ID="ViewOne" runat="server">
            One
         </asp:View>
         <asp:View ID="ViewTwo" runat="server">
            Two
         </asp:View>
         </asp:MultiView>
         <asp:ImageButton ID="btnBack" runat="server" ImageUrl="/assets/back_button.jpg"  OnClick="btnBack_Click" /> 
         <asp:ImageButton ID="btnNext" runat="server" ImageUrl="/assets/next_button.gif" OnClick="btnNext_Click" />
         <asp:ImageButton ID="btnSubmit" runat="server" ImageUrl="/assets/submit_button.gif" OnClick="btnSend_Click" />
    </div>
    </form>
</body>
</html>

Test2.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class test2 : System.Web.UI.Page
{
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        //PopulateSomeField();
    }

    protected override void OnPreRender(EventArgs e)
    {
        btnBack.Visible = MultiView2.ActiveViewIndex > 0;
        btnNext.Visible = MultiView2.ActiveViewIndex < MultiView2.Views.Count - 1;
        btnSubmit.Visible = MultiView2.ActiveViewIndex == MultiView2.Views.Count - 1;
        base.OnPreRender(e);
    }

    protected void btnBack_Click(object sender, EventArgs e)
    {
        MultiView2.ActiveViewIndex--;
    }

    protected void btnNext_Click(object sender, EventArgs e)
    {
        MultiView2.ActiveViewIndex++;
    }

    protected void btnSend_Click(object sender, EventArgs e)
    {
        Response.Write("submitted");
    }

}
2012-04-05 14:43
by Code Maverick
Thanks Scott, I edited and added some more code. Incredibly quick response btw - Brian 2012-04-05 14:50
@Brian - What is PopulateSomeField()? Is that relevant - Code Maverick 2012-04-05 14:52
@Brian - I commented out PopulateSomeField() and it still works fine for me - Code Maverick 2012-04-05 14:54
thanks for looking man. I'm really stuck now. I put break points on the btnNext, btnBack etc but the don't hit when in ViewTwo - Brian 2012-04-05 15:27
@Brian - I would comment out everything down to basically what I have above in the markup and in code and see if you can get it working bare bones. Then add pieces back in one by one to see what causes the issue - Code Maverick 2012-04-05 15:28
thanks for the advice. I'll give that a try now - Brian 2012-04-05 15:31
Ads