Nov 19, 2015, 1:17 PM
[CLOSED] ComboBox in Usercontrol return value
Hi,
i'm starting from this example https://examples3.ext.net/#/Layout/F..._UserControls/
my test.asxp
i'm starting from this example https://examples3.ext.net/#/Layout/F..._UserControls/
my test.asxp
<%@ Page Language="C#" %>
<%@ Import Namespace="EDM" %>
<%@ Register src="test.ascx" tagname="Address" tagprefix="uc1" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
this.BindCustomer(this.GetCustomer());
}
}
protected void Button1_Click(object sender, DirectEventArgs e)
{
string template = "{0}: {1}<br />";
StringBuilder sb = new StringBuilder(255);
sb.AppendFormat(template, "Customer ID", this.txtCustomerID.Value);
sb.AppendFormat(template, "First Name", this.txtFirstName.Text);
sb.AppendFormat(template, "Last Name", this.txtLastName.Text);
sb.AppendFormat(template, "Company", this.txtCompany.Text);
sb.AppendFormat(template, "Address1", this.ucShipping.StreetAddress);
sb.AppendFormat(template, "ch1", this.ucShipping.CountryID);
sb.AppendFormat(template, "IDContatto1", this.ucShipping.IDContatto);
sb.AppendFormat(template, "Address2", this.ucBilling.StreetAddress);
sb.AppendFormat(template, "ch21", this.ucBilling.CountryID);
sb.AppendFormat(template, "IDContatto2", this.ucBilling.IDContatto);
this.Label1.Html = sb.ToString();
}
public void BindCustomer(Customer customer)
{
this.txtCustomerID.Value = customer.ID;
this.txtFirstName.Text = customer.FirstName;
this.txtLastName.Text = customer.LastName;
this.txtCompany.Text = customer.Company;
this.ucShipping.StreetAddress = customer.ShippingAddress.StreetAddress;
this.ucShipping.ZipPostalCode = customer.ShippingAddress.ZipPostalCode;
this.ucShipping.City = customer.ShippingAddress.City;
this.ucShipping.CountryID = customer.ShippingAddress.Country.Code;
this.ucShipping.IDContatto = "222";
if (customer.BillingAddress != null)
{
this.ucBilling.StreetAddress = customer.ShippingAddress.StreetAddress;
this.ucBilling.ZipPostalCode = customer.ShippingAddress.ZipPostalCode;
this.ucBilling.City = customer.ShippingAddress.City;
this.ucBilling.CountryID = customer.ShippingAddress.Country.Code;
this.ucBilling.IDContatto = "1";
}
else
{
this.ucBilling.ShowCheckbox = true;
this.ucBilling.Checked = true;
this.ucBilling.CheckboxMessage = "Same as Shipping";
}
}
public Customer GetCustomer()
{
Customer customer = new Customer();
customer.ID = "08-1";
customer.FirstName = "Geoffrey";
customer.LastName = "McGill";
customer.Company = "Ext.NET, Inc.";
Address address = new Address();
address.StreetAddress = "#208, 10113 104 Street";
address.ZipPostalCode = "T5J 1A1";
address.City = "Edmonton";
Country country = new Country();
country = new Country();
country.Code = "CA";
country.Name = "Canada";
address.Country = country;
customer.ShippingAddress = address;
return customer;
}
public class Customer
{
public string ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Company { get; set; }
public Address BillingAddress { get; set; }
public Address ShippingAddress { get; set; }
}
public class Address
{
public string StreetAddress { get; set; }
public string ZipPostalCode { get; set; }
public string City { get; set; }
public Country Country { get; set; }
}
public class Country
{
public string Name { get; set; }
public string Code { get; set; }
}
</script>
<html>
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<title>BOOKSFLOW</title>
<link type="text/css" href="/css/stili.css" rel="stylesheet" />
<script type="text/javascript" src="/js/contatti.js"></script>
<!-- Bootstrap -->
<link href="/css/menu/style.css" rel="stylesheet" />
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="/css/menu/script.js"></script>
<style>
.nohidden {
overflow: initial !important;
}
#North-body {
overflow: initial !important;
}
</style>
</head>
<body id="body_principale">
<ext:ResourceManager ID="ResourceManager1" runat="server" InitScriptMode="Linked" ScriptMode="Debug" SourceFormatting="True" Theme="Crisp" />
<form id="form1" runat="server">
<ext:Label ID="Label1" runat="server" />
<ext:Hidden ID="txtCustomerID" runat="server" />
<ext:Window
ID="Window1"
runat="server"
Icon="User"
Closable="false"
Title="Customer Details"
Width="350"
Height="530"
Resizable="false"
BodyStyle="background-color:#fff;"
BodyPadding="5"
Layout="Anchor">
<Items>
<ext:TextField ID="txtFirstName" runat="server" FieldLabel="First Name" AllowBlank="false" />
<ext:TextField ID="txtLastName" runat="server" FieldLabel="Last Name" AllowBlank="false" />
<ext:TextField ID="txtCompany" runat="server" FieldLabel="Company" />
<ext:Panel ID="Panel1" runat="server" Header="false" Border="false" Layout="FitLayout">
<Content>
<uc1:address id="ucShipping" runat="server" title="SHIPPING ADDRESS" />
</Content>
</ext:Panel>
<ext:Panel ID="Panel2" runat="server" Header="false" Border="false" Layout="FitLayout">
<Content>
<uc1:address id="ucBilling" runat="server" title="BILLING ADDRESS" />
</Content>
</ext:Panel>
</Items>
<Buttons>
<ext:Button ID="Button1" runat="server" Text="Save" Icon="Disk">
<DirectEvents>
<Click OnEvent="Button1_Click">
<EventMask ShowMask="true" Msg="Saving..." MinDelay="500" />
</Click>
</DirectEvents>
</ext:Button>
</Buttons>
</ext:Window>
</form>
</body>
</html>
in test.ascx i've added new ComboBox field like this<%@ Control Language="C#" AutoEventWireup="true" CodeFile="test.ascx.cs" Inherits="test" %>
<ext:Panel
ID="Panel1"
runat="server"
BodyPadding="5"
Layout="AnchorLayout">
<Items>
<ext:Panel
ID="Panel2"
runat="server"
Border="false"
Header="false"
AnchorHorizontal="100%"
Layout="FormLayout">
<Items>
<ext:TextField ID="txtStreet" runat="server" FieldLabel="Street" />
<ext:TextField ID="txtZipPostalCode" runat="server" FieldLabel="Zip/Postal Code" />
<ext:TextField ID="txtCity" runat="server" FieldLabel="City" />
<ext:ComboBox ID="cbxCountry" runat="server" FieldLabel="Country">
<Items>
<ext:ListItem Text="Australia" Value="AU" />
<ext:ListItem Text="Canada" Value="CA" />
<ext:ListItem Text="United States" Value="US" />
</Items>
</ext:ComboBox>
<ext:ComboBox runat="server" ID="cmbIDContatto" Name="Intestazione" FieldLabel="Cliente" DisplayField="Intestazione" ValueField="IDContatto" TypeAhead="false" MultiSelect="false" HideBaseTrigger="false" MinChars="2" TriggerAction="Query" MarginSpec="0 5 0 0" ForceSelection="true" Width="300">
<ListConfig LoadingText="Searching..." Flex="1">
<ItemTpl ID="ItemTpl1" runat="server">
<Html>
<div class="search-item">
<p>({IDContatto}) - <span>{Intestazione}</span></p>
</div>
</Html>
</ItemTpl>
</ListConfig>
<Store>
<ext:Store ID="Store2" runat="server" AutoLoad="false">
<Proxy>
<ext:AjaxProxy Url="/handler/ListaContatti.ashx">
<ActionMethods Read="POST" />
<Reader>
<ext:JsonReader RootProperty="vw_Contatti" TotalProperty="total" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model ID="Model2" runat="server">
<Fields>
<ext:ModelField Name="IDContatto" />
<ext:ModelField Name="Intestazione" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</Items>
</ext:Panel>
</Items>
</ext:Panel>
test.ascx.csusing System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
public partial class test : System.Web.UI.UserControl
{
public string Title
{
get { return this.Panel1.Title; }
set { this.Panel1.Title = value; }
}
public string StreetAddress
{
get { return this.txtStreet.Text; }
set { this.txtStreet.Text = value; }
}
public string ZipPostalCode
{
get { return this.txtZipPostalCode.Text; }
set { this.txtZipPostalCode.Text = value; }
}
public string City
{
get { return this.txtCity.Text; }
set { this.txtCity.Text = value; }
}
public string CountryID
{
get { return this.cbxCountry.SelectedItems[0].Value; }
set { this.cbxCountry.Select((object)value); }
}
public string IDContatto
{
get { return this.cmbIDContatto.SelectedItems[0].Value; }
set { this.cmbIDContatto.Select((object)value); }
}
public bool ShowCheckbox
{
get
{
object obj = this.ViewState["ShowCheckbox"];
return (obj == null) ? false : (bool)obj;
}
set
{
this.ViewState["ShowCheckbox"] = value;
}
}
public bool Checked
{
get { return this.chkSame.Checked; }
set { this.chkSame.Checked = value; }
}
public string CheckboxMessage
{
get { return this.chkSame.BoxLabel; }
set { this.chkSame.BoxLabel = value; }
}
Checkbox chkSame = new Checkbox();
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
if (this.ShowCheckbox)
{
this.chkSame.ID = "chkSame";
this.chkSame.Checked = this.Checked;
this.chkSame.BoxLabel = this.CheckboxMessage;
this.chkSame.Listeners.Change.Handler = @"#{Panel2}.setVisible(!newValue);
#{Panel2}.doLayout();
if (!newValue) {
#{txtStreet}.focus();
}";
this.Panel1.Items.Insert(0, this.chkSame);
this.Panel2.Hidden = this.Checked;
}
}
}
}
Now, if i click on save button (after selected two different Clienti), it return same ID like this:Customer ID: 08-1
First Name: Geoffrey
Last Name: McGill
Company: Ext.NET, Inc.
Address1: #208, 10113 104 Street
ch1: CA
IDContatto1: 8 --FIRST ID SELECTED IN SHIPPING ADDRESS
Address2:
ch21: AU
IDContatto2: 8 ---SECOND ID SELECTED IN BILLING ADDRESS, BUT IS ALWAYS FIRST
Can you please help me?
Last edited by Daniil; Nov 23, 2015 at 9:05 AM.
Reason: [CLOSED]