PDA

View Full Version : [CLOSED] Problem with AjaxEvent in ComboBox



egof
Oct 15, 2008, 7:35 PM
This is my code:





<%@ Page Language="C#" AutoEventWireup="true" CodeFile="VendaBusca.aspx.cs" Inherits="VendaBusca" %>


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


<!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">


<link href="~/recursos/css/Default.css" rel="stylesheet" type="text/css" />


<style type="text/css">


.search-item {


font:normal 11px tahoma, arial, helvetica, sans-serif;


padding:3px 10px 3px 10px;


border:1px solid #fff;


border-bottom:1px solid #eeeeee;


white-space:normal;


color:#555;


}


.search-item h3 {


display:block;


font:inherit;


font-weight:bold;


color:#222;


}


.search-item h3 span {


float: right;


font-weight:normal;


margin:0 0 5px 5px;


width:100px;


display:block;


clear:none;


}





p { width:650px; }


.ext-ie .x-form-text {position:static !important;}





</style>


<title>Busca de Dados</title>


</head>


<body>


<form id="form1" runat="server">


<asp:ScriptManager ID="scriptManagerAspVendaBusca" runat="server"/>


<ext:ScriptManager ID="scriptManagerExtVendaBusca" runat="server"/>


<asp:UpdatePanel ID="UpdatePanel10" runat="server">


<Triggers>


<asp:PostBackTrigger ControlID="TextBox1" />


</Triggers>


<ContentTemplate>


<div style="vertical-align:top">


<ext:Store runat="server" ID="storeEntregador">


<Proxy>


<ext:HttpProxy Method="POST" Url="PessoasService.ashx" />


</Proxy>





<Reader>


<ext:JsonReader Root="plants" TotalProperty="totalCount" >


<Fields>


<ext:RecordField Name="nome" Type="String" />


<ext:RecordField Name="id" Type="String" />


</Fields>


</ext:JsonReader>


</Reader>


</ext:Store>


<div style="width:600px; top: 150px; left: 0px; position: absolute; height: 122px;">


<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc">





<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc">


<h3 style="margin-bottom:5px;">Search the plants</h3>








<ext:ComboBox runat="server" ID="comboBoxEntregador"


StoreID="storeEntregador"


DisplayField="nome"


ValueField="id"


TypeAhead="false"


LoadingText="Searching..."


Width="570"


PageSize="10"


HideTrigger="true"


ItemSelector="div.search-item"


MinChars="1">


<Template ID="Template1" runat="server">


<tpl for=".">


<div class="search-item">





<h3>{id}


{nome}





</h3>









</tpl>


</Template>





</ext:ComboBox>





<div style="padding-top:4px;">


Plants search (type '*' (asterisk) for showing all)












<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc">















<ext:Store runat="server" ID="storeCliente">


<Proxy>


<ext:HttpProxy Method="POST" Url="PessoasService.ashx" />


</Proxy>





<Reader>


<ext:JsonReader Root="plants" TotalProperty="totalCount" >


<Fields>


<ext:RecordField Name="nome" Type="String" />


<ext:RecordField Name="id" Type="String" />


</Fields>


</ext:JsonReader>


</Reader>


</ext:Store>


<div style="width:600px; top: 70px; left: 0px; position: absolute; height: 122px;">


<div class="x-box-tl"><div class="x-box-tr"><div class="x-box-tc">





<div class="x-box-ml"><div class="x-box-mr"><div class="x-box-mc">


<h3 style="margin-bottom:5px;">Search the plants</h3>








<ext:ComboBox runat="server" ID="comboBoxCliente"


StoreID="storeCliente"


DisplayField="nome"


ValueField="id"


TypeAhead="false"


LoadingText="Searching..."


Width="570"


PageSize="10"


HideTrigger="true"


ItemSelector="div.search-item"


MinChars="1"


OnItemChanged="buttonSalvarDados_Click">


<Template ID="Template2" runat="server">


<tpl for=".">


<div class="search-item">





<h3>{id}


{nome}





</h3>









</tpl>


</Template>


<AjaxEvents>


<Change OnEvent="buttonSalvarDados1_Click"></Change>


</AjaxEvents>





</ext:ComboBox>





<div style="padding-top:4px;">


Plants search (type '*' (asterisk) for showing all)












<div class="x-box-bl"><div class="x-box-br"><div class="x-box-bc">













<asp:Button ID="buttonSalvarDados" runat="server" Text="Salvar dados" onclick="buttonSalvarDados_Click"/>





<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>





</ContentTemplate>


</asp:UpdatePanel>





</form>


</body>


</html>





And this is my code-behind:






using System;


using System.Collections;


using System.Configuration;


using System.Data;


using System.Linq;


using System.Web;


using System.Web.Security;


using System.Web.UI;


using System.Web.UI.HtmlControls;


using System.Web.UI.WebControls;


using System.Web.UI.WebControls.WebParts;


using System.Xml.Linq;


using Coolite.Ext.Web;


public partial class VendaBusca : System.Web.UI.Page


{


protected void Page_Load(object sender, EventArgs e)


{


ConexaoMySQL.conectar();


}


protected void buttonSalvarDados_Click(object sender, EventArgs e)


{


Session["idEntregador"] = comboBoxEntregador.SelectedItem.Value.ToString();


Session["nomeEntregador"] = comboBoxEntregador.SelectedItem.Text.ToString();


Session["idCliente"] = comboBoxCliente.SelectedItem.Value.ToString();


Session["nomeCliente"] = comboBoxCliente.SelectedItem.Text.ToString();


TextBox1.Text = comboBoxCliente.SelectedItem.Value.ToString();


}


public void buttonSalvarDados1_Click(object sender, EventArgs e)


{


TextBox1.Text = comboBoxCliente.SelectedItem.Value.ToString();


}


}






My problem is when I select a item from "comboBoxCliente" and a press the key "tab"
and its call the "CHANGE AJAXEVENT" but my TextBox1 in not update with the right value!!!

Is a bug?

What is the problem?

Vladimir
Oct 16, 2008, 5:24 AM
Please note that You can update only Coolite controls during AjaxEvent (the ASP.NET textbox can't be updated)

geoffrey.mcgill
Oct 16, 2008, 11:21 AM
Hi egof,

As mentioned by Vladimir, the AjaxEvents can only "automatically" update Coolite Toolkit controls druing the response, but with a little JavaScript magic you can update anything on the Page.

The following example demonstrates how to update an <asp:TextBox> during an AjaxEvent.

Example


public void buttonSalvarDados1_Click(object sender, EventArgs e)
{
// Get the .ClientID of the TextBox. We always have to use the .ClientID,
// as it might be different than the controls .ID property.
string clientID = this.TextBox1.ClientID;

// Get the ComboBox value.
string value = this.ComboBox1.SelectedItem.Value.ToString();

// A simple Template with token to be replaced with our values.
// The "var t;" prefix is required to work-around a bug in the v0.6.0 release.
// The bug has been fixed and the work-around will not be required
// if using a release newer than v0.6.0.
// The work-around is also only required if the script starts with
// "Ext.get", "Ext.select" or "function(".
string template = "var t; Ext.get('{0}').dom.value = '{1}';";

// Add the TextBox update script to the response by calling .AddScript() on
// any Coolite Toolkit control or on the <ext:ScriptManager>.
this.ScriptManager1.AddScript(string.Format(templa te, clientID, value));
}

Hope this helps.