PDA

View Full Version : [CLOSED] Update TextField by Ajax Combobox



Oliver
May 29, 2012, 1:28 AM
Hello!
I have a combobox with an ajax event and I want to update the value of a textfield. I do the same thing with another combobox and works fine, but I donīt Know how to call the right event in the textfield.

Combobox Code:



<ext:ComboBox ID="dbIdTerceiro" runat="server" Editable="true" Height="20px" FieldLabel="Terceiro"
Width="500" ReadOnly="false" AnchorHorizontal="95%" LabelAlign="Right" QueryMode="Local"
DisplayField="cNmTerceiro" ValueField="nCdTerceiro" TriggerAction="Query" EmptyText="Selecionar..."
TypeAhead="true" ForceSelection="true">
<Listeners>
<Select Handler="#{dbIdTerceiroPagador}.clearValue(); #{StoreTerceiroPagador}.reload(); #{dbContato}.clearValue(); " />
</Listeners>
<Store>
<ext:Store ID="StoreTerceiro" runat="server" AutoLoad="true">
<Model>
<ext:Model ID="Model4" IDProperty="nCdTerceiro" runat="server">
<Fields>
<ext:ModelField Name="nCdTerceiro" Type="Int" />
<ext:ModelField Name="cNmTerceiro" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>



Textfield code that I need to be updated by the selection on the combobox. I need to call a DirectEvent to fill the field when the combobox "dbIdTerceiro" is changed:




<ext:TextField ID="dbContato" runat="server" FieldLabel="Contato" AllowBlank="false"
Width="400px" LabelAlign="Right" ReadOnly="false" EmptyText="Informe o nome e telefone">
</ext:TextField>

protected void posicionarContato(object sender, DirectEvent e)
{
if (this.dbIdTerceiro.SelectedItem.Value != "")
{
Terceiro objTerceiro = dc.Terceiros.FirstOrDefault(t1 => t1.nCdTerceiro == Convert.ToInt32(this.dbIdTerceiro.SelectedItem.Val ue));

this.dbContato.Text = ((objTerceiro.cNmContato == null) ? "" : objTerceiro.cNmContato) + ((objTerceiro.cTelefone1 == null) ? "" : objTerceiro.cTelefone1);
}
}



Plese, help me to include the listenner in the textfield.

Thanks in advance,

Oliver

Daniil
May 29, 2012, 4:02 AM
Hi,

Setting up the TextField Text property should be enough during DirectEvent.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.ComboBox1.GetStore();
store.DataSource = new object[]
{
new object[] { "1", "item1" },
new object[] { "2", "item2" },
new object[] { "3", "item3" }
};
store.DataBind();
}
}

protected void ComboBoxSelect(object sender, DirectEventArgs e)
{
this.TextField1.Text = (sender as ComboBox).SelectedItem.Value;
}
</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>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:ComboBox ID="ComboBox1" runat="server" ValueField="value">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="value" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
<Reader>
<ext:ArrayReader />
</Reader>
</ext:Store>
</Store>
<DirectEvents>
<Select OnEvent="ComboBoxSelect" />
</DirectEvents>
</ext:ComboBox>
<ext:TextField ID="TextField1" runat="server" />
</form>
</body>
</html>

Oliver
May 30, 2012, 12:30 AM
Hi,

Setting up the TextField Text property should be enough during DirectEvent.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
Store store = this.ComboBox1.GetStore();
store.DataSource = new object[]
{
new object[] { "1", "item1" },
new object[] { "2", "item2" },
new object[] { "3", "item3" }
};
store.DataBind();
}
}

protected void ComboBoxSelect(object sender, DirectEventArgs e)
{
this.TextField1.Text = (sender as ComboBox).SelectedItem.Value;
}
</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>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:ComboBox ID="ComboBox1" runat="server" ValueField="value">
<Store>
<ext:Store runat="server">
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="value" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
<Reader>
<ext:ArrayReader />
</Reader>
</ext:Store>
</Store>
<DirectEvents>
<Select OnEvent="ComboBoxSelect" />
</DirectEvents>
</ext:ComboBox>
<ext:TextField ID="TextField1" runat="server" />
</form>
</body>
</html>


Hi Daniil,

It works!

Thanks again!!!

Oliver