Change MultiView active view using ext:button

  1. #1

    Change MultiView active view using ext:button

    Hello,

    I have a Multiview with two views. Two buttons (one linkbutton and one ext:button) are placed into View1, both should change active view to View2 when clicked. The LinkButton works, the Ext button doesn't. What I've missed here?

    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 1;
        }
        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            MultiView1.ActiveViewIndex = 0;
        }
    </script>
    
    <!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>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        
        <form id="form1" runat="server">
        <div>
    
            <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
                <asp:View ID="View1" runat="server">
                    <p>This is View 1</p>
                    <p><asp:LinkButton ID="lbtn1" runat="server" OnClick="LinkButton1_Click" Width="145" Height="145" BorderStyle="Solid">
                        <span>LinkButton Goto View 2 Works</span></asp:LinkButton></p>
                    <p><ext:button Height="145px" Width="145px" runat="server" ID="lbtn2" Text="Ext Button Goto View 2<br/>Doesn't Work"
                        Scale="Large" LabelWidth="120" OnDirectClick="LinkButton1_Click" /></p>
                </asp:View>
                <asp:View ID="View2" runat="server">
                    <p>This is View 2</p>
                    <p><asp:LinkButton ID="lbtnBack" runat="server" OnClick="LinkButton2_Click" Width="145" Height="145" BorderStyle="Solid">
                        <span>Back to View 1</span></asp:LinkButton></p>
                </asp:View>
            </asp:MultiView>
       
        </div>
        </form>
    </body>
    </html>
    Thank you
    Regards
    Alex
  2. #2
    Hi Alex,

    There is a very essential difference between OnClick and OnDirectClick. OnClick is a regular ASP.NET PostBack event. OnDirectClick is a DirectEvent, i.e. an AJAX request.

    I am afraid it is not going to work to change the MultiView1's ActiveIndexIndex during a DirectEvent, but you can get the Ext.NET Button behaving as an ASP.NET button. For that please replace
    OnDirectClick="LinkButton1_Click"
    with
    OnClick="LinkButton1_Click" AutoPostBack="true"
    There is another approach and this also should work, theoretically.

    <ext:Container ID="Container1" runat="server">
        <Content>
            <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
                ...
            </asp:MultiView>
        </Content>
    </ext:Container>
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 1;
    
        if (X.IsAjaxRequest)
        {
            Container1.UpdateContent();
        }
    }
    Though, our best recommendation is to get rid of the MultiView control at all and replace it via a Container with a CardLayout.
    https://examples2.ext.net/#/Layout/CardLayout/Basic/
  3. #3
    Thank you Daniil, works as expected. I plan to change it to a panel with card layout ASAP.
    Regards
    Alex

Similar Threads

  1. Tabstrip and asp.net multiview
    By jmilton in forum 2.x Help
    Replies: 0
    Last Post: May 13, 2014, 8:13 PM
  2. Change tabpanel active tab from inner page
    By sskapci in forum 2.x Help
    Replies: 2
    Last Post: Mar 18, 2014, 7:29 AM
  3. [CLOSED] How toggle button keep active even after click on it
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 01, 2012, 4:54 PM
  4. Replies: 3
    Last Post: Feb 02, 2010, 6:32 PM
  5. Replies: 1
    Last Post: Jul 24, 2009, 2:52 AM

Tags for this Thread

Posting Permissions