[CLOSED] Problem when using combobox with autorefreshdata and asp:dropdownlist

  1. #1

    [CLOSED] Problem when using combobox with autorefreshdata and asp:dropdownlist

    I have the following situation in a page:

    - There is a combobox in which i use onrefreshdata, so that when the user types anything it's content is filtered in the server.
    - There is an asp:DropDownList. In this case i must use it instead of a combobox or selectbox because it renders as a html "select", and this page is used by our clients under ipad (ipad's safari has it's own way of letting the user choose an item from an html select, if i use a combobox or selectbox it functions the same way as on the pc, and it's hard to choose the items using the fingers).
    - When a value is selected in the combobox (change directevent), i need to change the content of the dropdownlist accoridng to the item that was selected in the combobox.
    - It works fine the first time, but then, if i try to type another thing in the combobox, i'm presented with a 500 server error.

    Any idea on what might be wrong?

    Follows an example:

    .aspx:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WSMXM.WebForm1" %>
    
    <!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>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <ext:ResourceManager runat="server"></ext:ResourceManager>
            <ext:ComboBox FieldLabel="Nome Fantasia" ID="myComboBox" runat="server" DisplayField="DS"
                ValueField="VALUE" TypeAhead="false" LoadingText="Buscando..." MinChars="1" HideTrigger="true"
                Width="280">
                <Store>
                    <ext:Store ID="Store1" runat="server" AutoLoad="false" OnRefreshData="Store_Refresh">
                        <Proxy>
                            <ext:PageProxy />
                        </Proxy>
                        <Reader>
                            <ext:JsonReader>
                                <Fields>
                                    <ext:RecordField Name="DS" Type="String" />
                                    <ext:RecordField Name="VALUE" Type="String" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
            <asp:DropDownList Width="200" Height="22" runat="server" ID="myDropDownList">
            </asp:DropDownList>
        </div>
        </form>
    </body>
    </html>

    .aspx.cs:

    public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                myComboBox.DirectEvents.Change.Event += new ComponentDirectEvent.DirectEventHandler(Change_Event);
            }
    
            void Change_Event(object sender, DirectEventArgs e)
            {
                myDropDownList.Items.Clear();
                myDropDownList.Items.Add(myComboBox.Value.ToString());
                myDropDownList.Update();
            }
    
            protected void Store_Refresh(object sender, StoreRefreshDataEventArgs e)
            {
    
                System.Data.DataTable dt = new System.Data.DataTable();
                dt.Columns.Add("DS");
                dt.Columns.Add("VALUE");
                System.Data.DataRow dr = dt.NewRow();
                dr["DS"] = "ABC";
                dr["VALUE"] = "1";
                dt.Rows.Add(dr);
                dr = dt.NewRow();
                dr["DS"] = "DEF";
                dr["VALUE"] = "2";
                dt.Rows.Add(dr);
    
                Store store = sender as Store;
                string filter = e.Parameters["query"];
    
                if (filter.Equals("."))
                {
                    store.DataSource = dt;
                    store.DataBind();
                    return;
                }
    
                var filteredList = (from x in dt.AsEnumerable()
                                    where (x["DS"]).ToString().ToUpper().StartsWith(filter.ToUpper())
                                    select new { VALUE = x["VALUE"].ToString(), DS = x["DS"].ToString() }
                    );
                store.DataSource = filteredList;
                store.DataBind();
    
            }
        }
    Last edited by Daniil; Aug 04, 2011 at 8:22 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Well, I have got 500 as well, but it looks like there is detailed info about the exception.
    Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
    You can just disable that feature:
    <%@ Page Language="C#" EnableEventValidation="false" %>
  3. #3
    I tried, but if i do this, it won't display any errors, but when i do a postback after i can't read the selected value from the dropdownlist, only from the combobox. I guess it's due to some conflict between the async postback of coolite and asp? Any hint on how to solve it? What is the proper way of working with both types of controls?
  4. #4
    Please try to set ViewStateMode="Enabled" for the DirectEvent.
  5. #5
    Tried to put it in the combobox and in the button that fires the event but the value os the selected item in the dropdownlist is still empty...

    like:

    MyComboBox.DirectEvents.Change.ViewStateMode = ViewStateMode.Enabled;
    MyButton.DirectEvents.Change.ViewStateMode = ViewStateMode.Enabled;
  6. #6
    For me all works correctly if viewstate is enabled

    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %> 
    <%@ Import Namespace="System.Linq" %>
    <%@ Import Namespace="System.Data" %>
     
    <!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>Untitled Page</title>
        
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                myComboBox.DirectEvents.Change.ViewStateMode = ViewStateMode.Enabled;
                myComboBox.DirectEvents.Change.Event += new ComponentDirectEvent.DirectEventHandler(Change_Event);
            }
     
            void Change_Event(object sender, DirectEventArgs e)
            {
                myDropDownList.Items.Clear();
                myDropDownList.Items.Add(myComboBox.Value.ToString());
                myDropDownList.Update();
            }
     
            protected void Store_Refresh(object sender, StoreRefreshDataEventArgs e)
            {
     
                System.Data.DataTable dt = new System.Data.DataTable();
                dt.Columns.Add("DS");
                dt.Columns.Add("VALUE");
                System.Data.DataRow dr = dt.NewRow();
                dr["DS"] = "ABC";
                dr["VALUE"] = "1";
                dt.Rows.Add(dr);
                dr = dt.NewRow();
                dr["DS"] = "DEF";
                dr["VALUE"] = "2";
                dt.Rows.Add(dr);
     
                Store store = sender as Store;
                string filter = e.Parameters["query"];
     
                if (filter.Equals("."))
                {
                    store.DataSource = dt;
                    store.DataBind();
                    return;
                }
     
                var filteredList = (from x in dt.AsEnumerable()
                                    where (x["DS"]).ToString().ToUpper().StartsWith(filter.ToUpper())
                                    select new { VALUE = x["VALUE"].ToString(), DS = x["DS"].ToString() }
                    );
                store.DataSource = filteredList;
                store.DataBind();
     
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <ext:ResourceManager runat="server"></ext:ResourceManager>
            <ext:ComboBox FieldLabel="Nome Fantasia" ID="myComboBox" runat="server" DisplayField="DS"
                ValueField="VALUE" TypeAhead="false" LoadingText="Buscando..." MinChars="1" HideTrigger="true"
                Width="280">
                <Store>
                    <ext:Store ID="Store1" runat="server" AutoLoad="false" OnRefreshData="Store_Refresh">
                        <Proxy>
                            <ext:PageProxy />
                        </Proxy>
                        <Reader>
                            <ext:JsonReader>
                                <Fields>
                                    <ext:RecordField Name="DS" Type="String" />
                                    <ext:RecordField Name="VALUE" Type="String" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
            <asp:DropDownList Width="200" Height="22" runat="server" ID="myDropDownList">
            </asp:DropDownList>
        </div>
        </form>
    </body>
    </html>
  7. #7
    Are you sure you can read the selected value from the dropdown?
    I added a button to the example to make it easier to see...

    To reproduce:
    - type "A" in the combobox and select the "ABC" item
    - the dropdown will be loaded with the "1" item
    - click the button
    - in the click directevent, the selectedvalue of the dropdown should be "1", but it's empty...

    <%@ Page Language="C#" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Import Namespace="System.Linq" %>
    <%@ Import Namespace="System.Data" %>
      
    <!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 id="Head1" runat="server">
        <title>Untitled Page</title>
         
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                myComboBox.DirectEvents.Change.ViewStateMode = ViewStateMode.Enabled;
                myButton.DirectEvents.Click.ViewStateMode = ViewStateMode.Enabled;
                myComboBox.DirectEvents.Change.Event += new ComponentDirectEvent.DirectEventHandler(Change_Event);
                myButton.DirectEvents.Click.Event += new ComponentDirectEvent.DirectEventHandler(Click_Event);
            }
    
            void Click_Event(object sender, DirectEventArgs e)
            {
                System.Diagnostics.Debug.Write(myDropDownList.SelectedValue);
                System.Diagnostics.Debugger.Break();
            }
      
            void Change_Event(object sender, DirectEventArgs e)
            {
                myDropDownList.Items.Clear();
                myDropDownList.Items.Add(myComboBox.Value.ToString());
                myDropDownList.Update();
            }
      
            protected void Store_Refresh(object sender, StoreRefreshDataEventArgs e)
            {
      
                System.Data.DataTable dt = new System.Data.DataTable();
                dt.Columns.Add("DS");
                dt.Columns.Add("VALUE");
                System.Data.DataRow dr = dt.NewRow();
                dr["DS"] = "ABC";
                dr["VALUE"] = "1";
                dt.Rows.Add(dr);
                dr = dt.NewRow();
                dr["DS"] = "DEF";
                dr["VALUE"] = "2";
                dt.Rows.Add(dr);
      
                Store store = sender as Store;
                string filter = e.Parameters["query"];
      
                if (filter.Equals("."))
                {
                    store.DataSource = dt;
                    store.DataBind();
                    return;
                }
      
                var filteredList = (from x in dt.AsEnumerable()
                                    where (x["DS"]).ToString().ToUpper().StartsWith(filter.ToUpper())
                                    select new { VALUE = x["VALUE"].ToString(), DS = x["DS"].ToString() }
                    );
                store.DataSource = filteredList;
                store.DataBind();
      
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <ext:ResourceManager ID="ResourceManager1" runat="server"></ext:ResourceManager>
            <ext:ComboBox FieldLabel="Nome Fantasia" ID="myComboBox" runat="server" DisplayField="DS"
                ValueField="VALUE" TypeAhead="false" LoadingText="Buscando..." MinChars="1" HideTrigger="true"
                Width="280">
                <Store>
                    <ext:Store ID="Store1" runat="server" AutoLoad="false" OnRefreshData="Store_Refresh">
                        <Proxy>
                            <ext:PageProxy />
                        </Proxy>
                        <Reader>
                            <ext:JsonReader>
                                <Fields>
                                    <ext:RecordField Name="DS" Type="String" />
                                    <ext:RecordField Name="VALUE" Type="String" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
            <asp:DropDownList Width="200" Height="22" runat="server" ID="myDropDownList">
            </asp:DropDownList>
            <ext:Button runat="server" ID="myButton" Text="Post"></ext:Button>
        </div>
        </form>
    </body>
    </html>
  8. #8
    I suggest tow wrap asp:DropDownList by ext container and update the content of the container

    <%@ Page Language="C#"  %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %> <%@ Import Namespace="System.Linq" %> <%@ Import Namespace="System.Data" %>
      
    <!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 id="Head1" runat="server">
        <title>Untitled Page</title>
         
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {            
                myComboBox.DirectEvents.Change.ViewStateMode = ViewStateMode.Enabled;            
                myComboBox.DirectEvents.Change.Event += new ComponentDirectEvent.DirectEventHandler(Change_Event);
                myButton.DirectEvents.Click.Event += new ComponentDirectEvent.DirectEventHandler(Click_Event);
            }
    
    
            void Click_Event(object sender, DirectEventArgs e)
            {
                System.Diagnostics.Debug.Write(myDropDownList.SelectedValue);
                System.Diagnostics.Debugger.Break();
            }
      
            void Change_Event(object sender, DirectEventArgs e)
            {
                myDropDownList.Items.Clear();
                myDropDownList.Items.Add(myComboBox.Value.ToString());
                Container1.UpdateContent();
            }
      
            protected void Store_Refresh(object sender, StoreRefreshDataEventArgs e)
            {
      
                System.Data.DataTable dt = new System.Data.DataTable();
                dt.Columns.Add("DS");
                dt.Columns.Add("VALUE");
                System.Data.DataRow dr = dt.NewRow();
                dr["DS"] = "ABC";
                dr["VALUE"] = "1";
                dt.Rows.Add(dr);
                dr = dt.NewRow();
                dr["DS"] = "DEF";
                dr["VALUE"] = "2";
                dt.Rows.Add(dr);
      
                Store store = sender as Store;
                string filter = e.Parameters["query"];
      
                if (filter.Equals("."))
                {
                    store.DataSource = dt;
                    store.DataBind();
                    return;
                }
      
                var filteredList = (from x in dt.AsEnumerable()
                                    where (x["DS"]).ToString().ToUpper().StartsWith(filter.ToUpper())
                                    select new { VALUE = x["VALUE"].ToString(), DS = x["DS"].ToString() }
                    );
                store.DataSource = filteredList;
                store.DataBind();
      
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <ext:ResourceManager ID="ResourceManager1" runat="server"></ext:ResourceManager>
            <ext:ComboBox FieldLabel="Nome Fantasia" ID="myComboBox" runat="server" DisplayField="DS"
                ValueField="VALUE" TypeAhead="false" LoadingText="Buscando..." MinChars="1" HideTrigger="true"
                Width="280">
                <Store>
                    <ext:Store ID="Store1" runat="server" AutoLoad="false" OnRefreshData="Store_Refresh">
                        <Proxy>
                            <ext:PageProxy />
                        </Proxy>
                        <Reader>
                            <ext:JsonReader>
                                <Fields>
                                    <ext:RecordField Name="DS" Type="String" />
                                    <ext:RecordField Name="VALUE" Type="String" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
            <ext:Container ID="Container1" runat="server">
                <Content>
                    <asp:DropDownList Width="200" Height="22" runat="server" ID="myDropDownList">
                    </asp:DropDownList>    
                </Content>
            </ext:Container>
            
            <ext:Button runat="server" ID="myButton" Text="Post"></ext:Button>
        </div>
        </form>
    </body>
    </html>
  9. #9
    Thanks. It worked.

Similar Threads

  1. Replies: 0
    Last Post: Feb 27, 2012, 5:26 AM
  2. Problem about combobox on DropDownList
    By zhangsir199 in forum 1.x Help
    Replies: 0
    Last Post: Mar 11, 2011, 12:39 AM
  3. Replies: 2
    Last Post: Mar 04, 2010, 7:12 PM
  4. [CLOSED] Dropdownlist in Gridpanel
    By LeeTheGreek in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Dec 08, 2009, 2:10 PM
  5. [CLOSED] Emulating a standard DropDownList
    By randy85253 in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Dec 05, 2009, 7:53 PM

Posting Permissions