[CLOSED] MultiCombo Change Event Not Saving ViewState

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] MultiCombo Change Event Not Saving ViewState

    In the first example below, I have a simple MultiCombo control that triggers a Change OnEvent. This event attempts to store the value of the selected items in viewstate. However, when I try to retrieve them, they're not there.

    In the second example, I've merely added another control to the page (ComboBox) with its own directevent. When this other control resides on the page, the value from the MultiCombo IS being successfully stored in viewstate and can be retrieved.

    I believe there is an issue with the MultiCombo's Change OnEvent. What do you think and what workaround do you advise?

    Example 1 (MultiCombo Not Storing ViewState)
    <%@ Page Language="vb" AutoEventWireup="false" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        
        Private Property MultiComboValues() As String
            Get
                Return ViewState("MultiComboValues")
            End Get
            Set(ByVal value As String)
                ViewState("MultiComboValues") = value
            End Set
        End Property
        
        Protected Sub Next_Click(sender As Object, e As DirectEventArgs)
            Dim index As Integer = Integer.Parse(e.ExtraParams("index"))
    
            If (index + 1) < Me.WizardPanel.Items.Count Then
                Me.WizardPanel.ActiveIndex = index + 1
                If Me.WizardPanel.ActiveIndex = 1 Then
                    TextField1.Text = MultiComboValues
                End If
            End If
    
            Me.CheckButtons()
        End Sub
        
        Protected Sub Prev_Click(sender As Object, e As DirectEventArgs)
            Dim index As Integer = Integer.Parse(e.ExtraParams("index"))
            
            If (index - 1) >= 0 Then
                WizardPanel.ActiveIndex = index - 1
            End If
            
            Me.CheckButtons()
        End Sub
    
        Private Sub CheckButtons()
            Dim index As Integer = Me.WizardPanel.ActiveIndex
    
            Me.btnNext.Disabled = If(index = Me.WizardPanel.Items.Count - 1, True, False)
            Me.btnPrev.Disabled = If(index = 0, True, False)
    
        End Sub
        
        Protected Sub MultiCombo_Change(ByVal sender As Object, ByVal e As DirectEventArgs)
            Dim values = String.Join(",", (From li In MultiCombo1.SelectedItems Select li.Value).ToArray)
            ViewState("MultiComboValues") = values
        End Sub
        
     </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Panel ID="WizardPanel" runat="server" Title="Example Wizard" Padding="15" Height="300"
            Layout="card" ActiveIndex="0">
            <Items>
                <ext:Panel ID="Panel1" runat="server" Border="false" Header="false">
                    <Items>
                        <ext:MultiCombo ID="MultiCombo1" runat="server">
                            <Items>
                                <ext:ListItem Text="Alpha" Value="1" />
                                <ext:ListItem Text="Bravo" Value="2" />
                                <ext:ListItem Text="Charlie" Value="3" />
                            </Items>
                            <DirectEvents>
                                <Change OnEvent="MultiCombo_Change" />
                            </DirectEvents>
                        </ext:MultiCombo>
                     </Items>
                </ext:Panel>
                <ext:Panel ID="Panel2" runat="server" Border="false" Header="false">
                    <Items>
                        <ext:TextField ID="TextField1" runat="server" />
                    </Items>
                </ext:Panel>
            </Items>
            <Buttons>
                <ext:Button ID="btnPrev" runat="server" Text="Prev" Disabled="true" Icon="PreviousGreen">
                    <DirectEvents>
                        <Click OnEvent="Prev_Click">
                            <ExtraParams>
                                <ext:Parameter Name="index" Value="#{WizardPanel}.items.indexOf(#{WizardPanel}.layout.activeItem)"
                                    Mode="Raw" />
                            </ExtraParams>
                        </Click>
                    </DirectEvents>
                </ext:Button>
                <ext:Button ID="btnNext" runat="server" Text="Next" Icon="NextGreen">
                    <DirectEvents>
                        <Click OnEvent="Next_Click">
                            <ExtraParams>
                                <ext:Parameter Name="index" Value="#{WizardPanel}.items.indexOf(#{WizardPanel}.layout.activeItem)"
                                    Mode="Raw" />
                            </ExtraParams>
                        </Click>
                    </DirectEvents>
                </ext:Button>
            </Buttons>
        </ext:Panel>
        </form>
    </body>
    </html>
    Example 2 (MultiCombo is storing viewstate)
    <%@ Page Language="vb" AutoEventWireup="false" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        
        Private Property MultiComboValues() As String
            Get
                Return ViewState("MultiComboValues")
            End Get
            Set(ByVal value As String)
                ViewState("MultiComboValues") = value
            End Set
        End Property
        
        Private Property ComboBoxValue() As String
            Get
                Return ViewState("ComboBoxValue")
            End Get
            Set(ByVal value As String)
                ViewState("ComboBoxValue") = value
            End Set
        End Property
    
    
        Protected Sub Next_Click(sender As Object, e As DirectEventArgs)
            Dim index As Integer = Integer.Parse(e.ExtraParams("index"))
    
            If (index + 1) < Me.WizardPanel.Items.Count Then
                Me.WizardPanel.ActiveIndex = index + 1
                If Me.WizardPanel.ActiveIndex = 1 Then
                    TextField1.Text = MultiComboValues
                    TextField2.Text = ComboBoxValue
                End If
            End If
    
            Me.CheckButtons()
        End Sub
        
        Protected Sub Prev_Click(sender As Object, e As DirectEventArgs)
            Dim index As Integer = Integer.Parse(e.ExtraParams("index"))
            
            If (index - 1) >= 0 Then
                WizardPanel.ActiveIndex = index - 1
            End If
            
            Me.CheckButtons()
        End Sub
    
        Private Sub CheckButtons()
            Dim index As Integer = Me.WizardPanel.ActiveIndex
    
            Me.btnNext.Disabled = If(index = Me.WizardPanel.Items.Count - 1, True, False)
            Me.btnPrev.Disabled = If(index = 0, True, False)
    
        End Sub
        
        Protected Sub MultiCombo_Change(ByVal sender As Object, ByVal e As DirectEventArgs)
            Dim values = String.Join(",", (From li In MultiCombo1.SelectedItems Select li.Value).ToArray)
            ViewState("MultiComboValues") = values
        End Sub
        
        Protected Sub ComboBox_Select(ByVal sender As Object, ByVal e As DirectEventArgs)
            Dim value = ComboBox1.SelectedItem.Value
            ViewState("ComboBoxValue") = value
        End Sub
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Panel ID="WizardPanel" runat="server" Title="Example Wizard" Padding="15" Height="300"
            Layout="card" ActiveIndex="0">
            <Items>
                <ext:Panel ID="Panel1" runat="server" Border="false" Header="false">
                    <Items>
                        <ext:MultiCombo ID="MultiCombo1" runat="server">
                            <Items>
                                <ext:ListItem Text="Alpha" Value="1" />
                                <ext:ListItem Text="Bravo" Value="2" />
                                <ext:ListItem Text="Charlie" Value="3" />
                            </Items>
                            <DirectEvents>
                                <Change OnEvent="MultiCombo_Change" />
                            </DirectEvents>
                        </ext:MultiCombo>
                        <ext:ComboBox ID="ComboBox1" runat="server">
                            <Items>
                                <ext:ListItem Text="Alpha" Value="1" />
                                <ext:ListItem Text="Bravo" Value="2" />
                                <ext:ListItem Text="Charlie" Value="3" />
                            </Items>
                            <DirectEvents>
                                <Select OnEvent="ComboBox_Select" />
                            </DirectEvents>
                        </ext:ComboBox>
                    </Items>
                </ext:Panel>
                <ext:Panel ID="Panel2" runat="server" Border="false" Header="false">
                    <Items>
                        <ext:TextField ID="TextField1" runat="server" />
                        <ext:TextField ID="TextField2" runat="server" />
                    </Items>
                </ext:Panel>
            </Items>
            <Buttons>
                <ext:Button ID="btnPrev" runat="server" Text="Prev" Disabled="true" Icon="PreviousGreen">
                    <DirectEvents>
                        <Click OnEvent="Prev_Click">
                            <ExtraParams>
                                <ext:Parameter Name="index" Value="#{WizardPanel}.items.indexOf(#{WizardPanel}.layout.activeItem)"
                                    Mode="Raw" />
                            </ExtraParams>
                        </Click>
                    </DirectEvents>
                </ext:Button>
                <ext:Button ID="btnNext" runat="server" Text="Next" Icon="NextGreen">
                    <DirectEvents>
                        <Click OnEvent="Next_Click">
                            <ExtraParams>
                                <ext:Parameter Name="index" Value="#{WizardPanel}.items.indexOf(#{WizardPanel}.layout.activeItem)"
                                    Mode="Raw" />
                            </ExtraParams>
                        </Click>
                    </DirectEvents>
                </ext:Button>
            </Buttons>
        </ext:Panel>
        </form>
    </body>
    </html>
    Last edited by Daniil; Dec 01, 2011 at 7:34 PM. Reason: [CLOSED]
  2. #2
    Hi,

    By default a DirectEvent doesn't send ViewState.

    To change it please set up ViewStateMode="Enabled" for a DirectEvent.
  3. #3
    Adding that line ('ViewStateMode="Enabled"') does not cause this to work. Any other ideas?
  4. #4
    ViewStateMode="Enabled" should be set up for both DirectEvents: Change and Click (next button).
  5. #5
    I have the viewstaemode enabled in the web config:

    <extnet theme="Default" ajaxViewStateMode="Enabled" scriptMode="Release" licenseKey=""  />
    Your reply assumes you were able to get my example working by following your own suggestions. Is this the case?
    Last edited by geoffrey.mcgill; Nov 29, 2011 at 4:27 PM.
  6. #6
    Quote Originally Posted by Daniil View Post
    ViewStateMode="Enabled" should be set up for both DirectEvents: Change and Click (next button).
    Setting for the Change DirectEvent is enough.

    And yes, I've checked - it works with it.

    Regarding to a web.config.

    ajaxViewStateMode : ViewStateMode
    Specifies whether the ViewState should be returned and updated on the client during an DirectEvent.
    The Default value is to Exclude the ViewState from the Response.
    Default is 'Default'. Options include [Default|Exclude|Include]
    You should set up the "Include" option.
  7. #7
    I tried switching the ajaxViewStateMode to "Include" but I received a parse error. It says the valid options are "Default/Disabled/Enabled". Can you clarify how the config file should read?

    Also, can you post the code where you were able to get my example working? That would be a big help.

    Thanks.
  8. #8
    Quote Originally Posted by garrisrd View Post
    Also, can you post the code where you were able to get my example working? That would be a big help.
    Sure, here it is.

    Example
    <%@ Page Language="vb" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <script runat="server">
         
        Private Property MultiComboValues() As String
            Get
                Return ViewState("MultiComboValues")
            End Get
            Set(ByVal value As String)
                ViewState("MultiComboValues") = value
            End Set
        End Property
         
        Protected Sub Next_Click(sender As Object, e As DirectEventArgs)
            Dim index As Integer = Integer.Parse(e.ExtraParams("index"))
     
            If (index + 1) < Me.WizardPanel.Items.Count Then
                Me.WizardPanel.ActiveIndex = index + 1
                If Me.WizardPanel.ActiveIndex = 1 Then
                    TextField1.Text = MultiComboValues
                End If
            End If
     
            Me.CheckButtons()
        End Sub
         
        Protected Sub Prev_Click(sender As Object, e As DirectEventArgs)
            Dim index As Integer = Integer.Parse(e.ExtraParams("index"))
             
            If (index - 1) >= 0 Then
                WizardPanel.ActiveIndex = index - 1
            End If
             
            Me.CheckButtons()
        End Sub
     
        Private Sub CheckButtons()
            Dim index As Integer = Me.WizardPanel.ActiveIndex
     
            Me.btnNext.Disabled = If(index = Me.WizardPanel.Items.Count - 1, True, False)
            Me.btnPrev.Disabled = If(index = 0, True, False)
     
        End Sub
         
        Protected Sub MultiCombo_Change(ByVal sender As Object, ByVal e As DirectEventArgs)
            Dim values = String.Join(",", (From li In MultiCombo1.SelectedItems Select li.Value).ToArray)
            ViewState("MultiComboValues") = values
        End Sub
         
     </script>
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Panel 
                ID="WizardPanel" 
                runat="server" 
                Title="Example Wizard" 
                Padding="15" 
                Height="300"
                Layout="card" 
                ActiveIndex="0">
                <Items>
                    <ext:Panel runat="server" Border="false" Header="false">
                        <Items>
                            <ext:MultiCombo ID="MultiCombo1" runat="server">
                                <Items>
                                    <ext:ListItem Text="Alpha" Value="1" />
                                    <ext:ListItem Text="Bravo" Value="2" />
                                    <ext:ListItem Text="Charlie" Value="3" />
                                </Items>
                                <DirectEvents>
                                    <Change OnEvent="MultiCombo_Change" ViewStateMode="Enabled" />
                                </DirectEvents>
                            </ext:MultiCombo>
                         </Items>
                    </ext:Panel>
                    <ext:Panel runat="server" Border="false" Header="false">
                        <Items>
                            <ext:TextField ID="TextField1" runat="server" />
                        </Items>
                    </ext:Panel>
                </Items>
                <Buttons>
                    <ext:Button
                        ID="btnPrev"
                        runat="server" 
                        Text="Prev" 
                        Disabled="true" 
                        Icon="PreviousGreen">
                        <DirectEvents>
                            <Click OnEvent="Prev_Click">
                                <ExtraParams>
                                    <ext:Parameter 
                                        Name="index" 
                                        Value="#{WizardPanel}.items.indexOf(#{WizardPanel}.layout.activeItem)"
                                        Mode="Raw" />
                                </ExtraParams>
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                    <ext:Button 
                        ID="btnNext" 
                        runat="server" 
                        Text="Next" 
                        Icon="NextGreen">
                        <DirectEvents>
                            <Click OnEvent="Next_Click">
                                <ExtraParams>
                                    <ext:Parameter 
                                        Name="index" 
                                        Value="#{WizardPanel}.items.indexOf(#{WizardPanel}.layout.activeItem)"
                                        Mode="Raw" />
                                </ExtraParams>
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:Panel>
        </form>
    </body>
    </html>
  9. #9
    Quote Originally Posted by garrisrd View Post
    I tried switching the ajaxViewStateMode to "Include" but I received a parse error. It says the valid options are "Default/Disabled/Enabled". Can you clarify how the config file should read?
    Yes, I was wrong. We should correct the sample Web.config. Thanks for the report.

    But it works for me with the
    ajaxViewStateMode="Enabled"
    option.

    Example
    <?xml version="1.0"?>
    <configuration>
        <configSections>
            <section name="extnet" type="Ext.Net.GlobalConfig" requirePermission="false"/>
        </configSections>
        <extnet ajaxViewStateMode="Enabled" />
    
    ...
    Though I'd recommend you to enable ViewState for a separate DirectEvent when it really needs or avoid ViewState at all - for example, use Session instead. The reason - ViewState can decrease application performance.
  10. #10
    Sorry, but the sample code you provided does not work when I try to run it.

    Let me clarify what should be happening so we're both on the same page.

    After you check one or two of the items in the multicombo box and click the next button, the values for those items should appear in the text box. That's not happening even with the code you provided.

    Are you certain you're seeing those list item values appear in the textbox? If so, what do I need to do to get your code to run?

    Rick
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 4
    Last Post: Jul 20, 2013, 7:01 PM
  2. [CLOSED] Editable column on grid: how to raise an event for saving
    By digitek in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Mar 13, 2012, 11:02 AM
  3. Replies: 0
    Last Post: Dec 12, 2011, 2:38 PM
  4. [CLOSED] [1.0] MultiCombo Change listener not working as expected
    By jmcantrell in forum 1.x Legacy Premium Help
    Replies: 11
    Last Post: Aug 20, 2010, 3:06 PM
  5. How to update viewstate in ajax event?
    By bruce in forum 1.x Help
    Replies: 1
    Last Post: Feb 08, 2009, 11:00 PM

Tags for this Thread

Posting Permissions