PDA

View Full Version : [CLOSED] combobox value disappear after button click



matrixwebtech
Dec 19, 2014, 5:35 AM
Hi
I have a combobox and a button ,and the button set with AutoPostback="true",after click on button combobox value disappear,please run the test case,also I found EmptyValue property not present in combobox.

Sample Aspx

<html>

<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" DisableViewState="false" />
<ext:ComboBox runat="server" ID="cmpDepartment" Editable="true" DisplayField="DepartmentName" ValueField="DepartmentID" TypeAhead="true"
EmptyText="All">
<Triggers>
<ext:FieldTrigger Icon="Clear" HideTrigger="true">
</ext:FieldTrigger>

</Triggers>
<Listeners>
<Select Handler="this.getTrigger(0).show();" />
<BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
<TriggerClick Handler="if (index == 0) {
this.clearValue();
this.getTrigger(0).hide();
}" />
</Listeners>
<Store>
<ext:Store
runat="server"
ID="DepartmentStore">

<Model>
<ext:Model ID="Model1" runat="server" IDProperty="DepartmentID">
<Fields>
<ext:ModelField Name="DepartmentID" Type="Int" />
<ext:ModelField Name="DepartmentName" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>

</ext:ComboBox>
<ext:DisplayField runat="server" ID="df" PaddingSpec="0 0 0 25" Html="&nbsp;"></ext:DisplayField>
<ext:Button runat="server" ID="btn" OnClick="btn_Click" Text="Click" AutoPostBack="true"></ext:Button>
</form>
</body>
</html>
Sample Code


public partial class delayed_event : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadCombo();
}
}

private void LoadCombo()
{
Department d ;
List<Department> _d = new List<Department>();
for (int i = 0; i <= 4; i++)
{
d = new Department();
d.DepartmentID = i;
d.DepartmentName = "Department - " + i.ToString();
_d.Add(d);
}

DepartmentStore.DataSource = _d;
DepartmentStore.DataBind();
}

protected void btn_Click(object sender, EventArgs e)
{

}


}

public class Department
{
public int DepartmentID { get; set; }
public string DepartmentName { get; set; }
}

Daniil
Dec 19, 2014, 6:56 AM
Hi @matrixwebtech,

You should replace

if (!IsPostBack)
with

if (!X.IsAjaxRequest)

Otherwise, the ComboBox's Store is just not binding to the data on PostBack.

matrixwebtech
Dec 19, 2014, 7:08 AM
Hi ,Daniil
Change according your suggestion ,now its working.but there are one problem.

1.I select a value from combobox,and the trigger button visible as expected.
2.click on button ,trigger button disappear.
how to fix this?

Daniil
Dec 19, 2014, 7:12 AM
I would try FireSelectOnLoad="true" for the ComboBox.

matrixwebtech
Dec 19, 2014, 7:20 AM
thank you very much for help.there are many small small tricks in EXT.Net .please close this thread.

matrixwebtech
Feb 12, 2015, 3:28 PM
I add after data bind in LoadCombo() function bellow code to add a All Option to the combo


DepartmentStore.DataSource = _d;
DepartmentStore.DataBind();
this.cmpDepartment.SelectedItems.Clear();
this.cmpDepartment.Items.Insert(0, new Ext.Net.ListItem { Text = "All", Value = "0" });
this.cmpDepartment.SelectedItems.Add(new Ext.Net.ListItem { Index = 0 });

All option added.but when I click on button selected item always lost and always All get selected.without adding All button click code works fine.

matrixwebtech
Feb 13, 2015, 2:13 PM
any thought ?

Daniil
Feb 13, 2015, 7:59 PM
Mm, I don't quite understand the issue.

Please provide a full test case. Then we could investigate.

matrixwebtech
Feb 14, 2015, 3:07 PM
Please try bellow code


<ext:ComboBox runat="server" ID="cmdtest" Editable="true" DisplayField="DepartmentName" ValueField="DepartmentID" TypeAhead="true"
EmptyText="All">
<Triggers>
<ext:FieldTrigger Icon="Clear" HideTrigger="true">
</ext:FieldTrigger>

</Triggers>
<Listeners>
<Select Handler="this.getTrigger(0).show();" />
<BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
<TriggerClick Handler="if (index == 0) {
this.clearValue();
this.getTrigger(0).hide();
}" />
</Listeners>
<Store>
<ext:Store
runat="server"
ID="stest">

<Model>
<ext:Model ID="Model1" runat="server" IDProperty="DepartmentID">
<Fields>
<ext:ModelField Name="DepartmentID" Type="Int" />
<ext:ModelField Name="DepartmentName" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>

</ext:ComboBox>
<ext:Button runat="server" ID="btnShow" Text="Show" OnClick="btnShow_Click" AutoPostBack="true">



public partial class test : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{

if (!X.IsAjaxRequest)
{

LoadCombo();


}

}




protected void btnShow_Click(object sender, EventArgs e)
{


}

private void LoadCombo()
{
Department d;
List<Department> _d = new List<Department>();
for (int i = 0; i <= 4; i++)
{
d = new Department();
d.DepartmentID = i;
d.DepartmentName = "Department - " + i.ToString();
_d.Add(d);
}


stest.DataSource = _d;
stest.DataBind();

this.cmdtest.SelectedItems.Clear();
this.cmdtest.Items.Insert(0, new Ext.Net.ListItem { Text = "All", Value = "0" });
this.cmdtest.SelectedItems.Add(new Ext.Net.ListItem { Index = 0 });
}
}

public class Department
{
public int DepartmentID { get; set; }
public string DepartmentName { get; set; }
}

1. Run this code and select ,combobox first item get selected automatically.
2. select a option suppose Department - 4,click on button again All option get selected.

but if I remove

this.cmdtest.SelectedItems.Clear();
this.cmdtest.Items.Insert(0, new Ext.Net.ListItem { Text = "All", Value = "0" });
this.cmdtest.SelectedItems.Add(new Ext.Net.ListItem { Index = 0 });
from LoadCombo() all works fine.

Daniil
Feb 16, 2015, 7:09 AM
Please try to set QueryMode="Local" for the ComboBox.