233 lines
6.6 KiB
C#
233 lines
6.6 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// evento valore selezionato
|
|
/// </summary>
|
|
public event EventHandler eh_valSelezionato;
|
|
|
|
/// <summary>
|
|
/// UID formattato con "_"
|
|
/// </summary>
|
|
public string uid
|
|
{
|
|
get
|
|
{
|
|
// fix brutale: nelle pagine master c'è un ctl00_ iniziale di troppo...
|
|
return this.UniqueID.Replace("$", "_").Replace("ctl00_", "").Replace("ctl01_", "");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// avvio pagina
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
ClientScriptManager script = Page.ClientScript;
|
|
if (!script.IsClientScriptBlockRegistered(this.GetType(), uid + "_ace"))
|
|
{
|
|
string pre = "<script type='text/javascript'>";
|
|
string scrVal = "function " + uid + "_SetSelectedValue(source, eventArgs) { ";
|
|
scrVal += " document.getElementById('" + uid + "_hiddenFieldID').value = eventArgs.get_value(); ";
|
|
scrVal += " document.getElementById('" + uid + "_btnPost').click(); ";
|
|
scrVal += " }";
|
|
string post = "</script>";
|
|
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);
|
|
}
|
|
/// <summary>
|
|
/// salvo valore selezionato!
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void hiddenFieldID_TextChanged(object sender, EventArgs e)
|
|
{
|
|
_valore = hiddenFieldID.Text;
|
|
if (eh_valSelezionato!= null)
|
|
{
|
|
eh_valSelezionato(this, new EventArgs());
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// valore selezionato dal controllo (RW local)
|
|
/// </summary>
|
|
protected string _valore
|
|
{
|
|
get
|
|
{
|
|
return utils.obj.StringSessionObj(uid + "_sel");
|
|
}
|
|
set
|
|
{
|
|
utils.obj.setSessionVal(uid+ "_sel", value);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// valore (chiave) selezionato dal controllo (R public)
|
|
/// </summary>
|
|
public string valore
|
|
{
|
|
get
|
|
{
|
|
return hiddenFieldID.Text;
|
|
}
|
|
set
|
|
{
|
|
hiddenFieldID.Text = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// label selezionato dal controllo (R public)
|
|
/// </summary>
|
|
public string label
|
|
{
|
|
get
|
|
{
|
|
return txtValue.Text;
|
|
}
|
|
set
|
|
{
|
|
txtValue.Text = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// num minimo caratteri x autocomplete
|
|
/// </summary>
|
|
public Int32 minCharAutocomplete
|
|
{
|
|
set
|
|
{
|
|
txtValueAce.MinimumPrefixLength = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// path del webservice
|
|
/// </summary>
|
|
public string ServicePath
|
|
{
|
|
set
|
|
{
|
|
txtValueAce.ServicePath = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// metodo da invocare x autocompletamento
|
|
/// </summary>
|
|
public string ServiceMethod
|
|
{
|
|
set
|
|
{
|
|
txtValueAce.ServiceMethod = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// imposta visibilità della textBox delle chiavi
|
|
/// </summary>
|
|
public bool showKey
|
|
{
|
|
set
|
|
{
|
|
if (!value)
|
|
{
|
|
hiddenFieldID.Width = Unit.Pixel(0);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// imposta la stringa tooltip
|
|
/// </summary>
|
|
public string toolTip
|
|
{
|
|
set
|
|
{
|
|
txtValue.ToolTip = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// salva evento selezione
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void btnPost_Click(object sender, EventArgs e)
|
|
{
|
|
_valore = hiddenFieldID.Text;
|
|
if (eh_valSelezionato != null)
|
|
{
|
|
eh_valSelezionato(this, new EventArgs());
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// in caso di modifica del solo valore text... a vuoto tipicamente...
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
protected void txtValue_TextChanged(object sender, EventArgs e)
|
|
{
|
|
if (txtValue.Text.Trim() == "")
|
|
{
|
|
hiddenFieldID.Text = "";
|
|
_valore = "";
|
|
if (eh_valSelezionato != null)
|
|
{
|
|
eh_valSelezionato(this, new EventArgs());
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// larghezza textbox in unità EM
|
|
/// </summary>
|
|
public int textEmWidht
|
|
{
|
|
set
|
|
{
|
|
txtValue.Width = Unit.Parse(string.Format("{0}em", value));
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// imposta il focus sulla textBox
|
|
/// </summary>
|
|
public void setFocus()
|
|
{
|
|
txtValue.Focus();
|
|
}
|
|
/// <summary>
|
|
/// permette di passare altri parametri di contesto al metodo invocato x autocomplete
|
|
/// </summary>
|
|
public string contextKey
|
|
{
|
|
get
|
|
{
|
|
return txtValueAce.ContextKey;
|
|
}
|
|
set
|
|
{
|
|
txtValueAce.ContextKey = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// tabIndex del controllo
|
|
/// </summary>
|
|
public short TabIndex
|
|
{
|
|
set
|
|
{
|
|
txtValue.TabIndex = value;
|
|
}
|
|
}
|
|
}
|
|
} |