using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using ETS_Data; namespace ETS_WS.WebUserControls { public partial class mod_textAutocomplete : System.Web.UI.UserControl { /// /// evento valore selezionato /// public event EventHandler eh_valSelezionato; /// /// UID formattato con "_" /// public string uid { get { // fix brutale: nelle pagine master c'è un ctl00_ iniziale di troppo... return this.UniqueID.Replace("$", "_").Replace("ctl00_", "").Replace("ctl01_", ""); } } /// /// avvio pagina /// /// /// protected void Page_Load(object sender, EventArgs e) { ClientScriptManager script = Page.ClientScript; if (!script.IsClientScriptBlockRegistered(this.GetType(), uid + "_ace")) { string pre = ""; string fullScript = string.Format("{0} {1} {2}", pre, scrVal, post); script.RegisterClientScriptBlock(this.GetType(), uid + "_ace", fullScript); } hiddenFieldID.ID = hiddenFieldID.ID.Replace("$", "_"); btnPost.ID = btnPost.ID.Replace("$", "_"); txtValueAce.OnClientItemSelected = string.Format("{0}_SetSelectedValue", uid); } /// /// salvo valore selezionato! /// /// /// protected void hiddenFieldID_TextChanged(object sender, EventArgs e) { _valore = hiddenFieldID.Text; if (eh_valSelezionato!= null) { eh_valSelezionato(this, new EventArgs()); } } /// /// valore selezionato dal controllo (RW local) /// protected string _valore { get { return utils.obj.StringSessionObj(uid + "_sel"); } set { utils.obj.setSessionVal(uid+ "_sel", value); } } /// /// valore (chiave) selezionato dal controllo (R public) /// public string valore { get { return hiddenFieldID.Text; } set { hiddenFieldID.Text = value; } } /// /// label selezionato dal controllo (R public) /// public string label { get { return txtValue.Text; } set { txtValue.Text = value; } } /// /// num minimo caratteri x autocomplete /// public Int32 minCharAutocomplete { set { txtValueAce.MinimumPrefixLength = value; } } /// /// path del webservice /// public string ServicePath { set { txtValueAce.ServicePath = value; } } /// /// metodo da invocare x autocompletamento /// public string ServiceMethod { set { txtValueAce.ServiceMethod = value; } } /// /// imposta visibilità della textBox delle chiavi /// public bool showKey { set { if (!value) { hiddenFieldID.Width = Unit.Pixel(0); } } } /// /// imposta la stringa tooltip /// public string toolTip { set { txtValue.ToolTip = value; } } /// /// salva evento selezione /// /// /// protected void btnPost_Click(object sender, EventArgs e) { _valore = hiddenFieldID.Text; if (eh_valSelezionato != null) { eh_valSelezionato(this, new EventArgs()); } } /// /// in caso di modifica del solo valore text... a vuoto tipicamente... /// /// /// protected void txtValue_TextChanged(object sender, EventArgs e) { if (txtValue.Text.Trim() == "") { hiddenFieldID.Text = ""; _valore = ""; if (eh_valSelezionato != null) { eh_valSelezionato(this, new EventArgs()); } } } /// /// larghezza textbox in unità EM /// public int textEmWidht { set { txtValue.Width = Unit.Parse(string.Format("{0}em", value)); } } /// /// imposta il focus sulla textBox /// public void setFocus() { txtValue.Focus(); } /// /// permette di passare altri parametri di contesto al metodo invocato x autocomplete /// public string contextKey { get { return txtValueAce.ContextKey; } set { txtValueAce.ContextKey = value; } } /// /// tabIndex del controllo /// public short TabIndex { set { txtValue.TabIndex = value; } } } }