inserito autocomplete
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="mod_autocomplete.ascx.cs" Inherits="GMW.WebUserControls.mod_autocomplete" %>
|
||||
<%if (false)
|
||||
{ %>
|
||||
<webopt:BundleReference ID="BundleReference1" runat="server" Path="~/Content/css" />
|
||||
<webopt:BundleReference ID="BundleReference2" runat="server" Path="~/Content/themes/base/css" />
|
||||
<%} %>
|
||||
|
||||
<script>
|
||||
$(function () {
|
||||
$("#<%=txtSelezione.ClientID %>").autocomplete({
|
||||
source: function (request, response) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
url: "<%=txtServiceUrl.Text %>",
|
||||
data: "{'prefixText':'" + request.term + "'}",
|
||||
dataType: "json",
|
||||
async: true,
|
||||
success: function (data) {
|
||||
//response(data.d);
|
||||
response($.map(data.d, function (item) {
|
||||
return {
|
||||
label: item.split('#')[0],
|
||||
val: item.split('#')[1]
|
||||
}
|
||||
}))
|
||||
},
|
||||
error: function (result) {
|
||||
alert("Impossibile caricare i dati!");
|
||||
}
|
||||
});
|
||||
},
|
||||
select: function (e, i) {
|
||||
$("#<%=hiddenFieldID.ClientID %>").val(i.item.val);
|
||||
$("#<%=txtSelezione.ClientID %>").val(i.item.label);
|
||||
$("#<%=btnPost.ClientID %>").click();
|
||||
},
|
||||
//minLength: 2
|
||||
minLength: <%=txtMinCharAutoCom.Text %>
|
||||
});
|
||||
});
|
||||
var prm = Sys.WebForms.PageRequestManager.getInstance();
|
||||
prm.add_endRequest(function () {
|
||||
$(function () {
|
||||
// chiamate jquery da rieseguire post ajax update x partial page render
|
||||
$(function () {
|
||||
$("#<%=txtSelezione.ClientID %>").autocomplete({
|
||||
source: function (request, response) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
contentType: "application/json; charset=utf-8",
|
||||
url: "<%=txtServiceUrl.Text %>",
|
||||
data: "{'prefixText':'" + request.term + "'}",
|
||||
dataType: "json",
|
||||
async: true,
|
||||
success: function (data) {
|
||||
//response(data.d);
|
||||
response($.map(data.d, function (item) {
|
||||
return {
|
||||
label: item.split('#')[0],
|
||||
val: item.split('#')[1]
|
||||
}
|
||||
}))
|
||||
},
|
||||
error: function (result) {
|
||||
alert("Impossibile caricare i dati!!!");
|
||||
}
|
||||
});
|
||||
},
|
||||
select: function (e, i) {
|
||||
$("#<%=hiddenFieldID.ClientID %>").val(i.item.val);
|
||||
$("#<%=txtSelezione.ClientID %>").val(i.item.label);
|
||||
$("#<%=btnPost.ClientID %>").click();
|
||||
},
|
||||
//minLength: 2
|
||||
minLength: <%=txtMinCharAutoCom.Text %>
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<%--controlli "principali"--%>
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">
|
||||
<asp:Label runat="server" ID="lblField" Text="Cerca:" Font-Size="0.8em" AssociatedControlID="txtSelezione" />
|
||||
<asp:Button runat="server" ID="btnPost" OnClick="btnPost_Click" Visible="false" Text="+" />
|
||||
</span>
|
||||
<asp:TextBox runat="server" ID="txtSelezione" CssClass="searchinput form-control" OnTextChanged="txtSelezione_TextChanged" AutoPostBack="True" TextMode="SingleLine" AutoCompleteType="Search" />
|
||||
<asp:TextBox runat="server" ID="hiddenFieldID" AutoPostBack="true" OnTextChanged="hiddenFieldID_TextChanged" Visible="true" ViewStateMode="Enabled" Width="0em" Font-Size="6pt" BackColor="Transparent" BorderStyle="None" />
|
||||
<%--controlli "accessori"--%>
|
||||
<asp:TextBox runat="server" ID="txtMinCharAutoCom" Text="2" Visible="false" Width="1em" />
|
||||
<asp:TextBox runat="server" ID="txtServiceUrl" Text="Services/WS_data.asmx/Test" Visible="false" Width="1em" />
|
||||
<span class="input-group-addon">
|
||||
<asp:LinkButton runat="server" ID="lnkReset" Text="X" type="button" OnClick="lnkReset_Click" Font-Size="0.8em" />
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.ui-autocomplete-category {
|
||||
font-weight: bold;
|
||||
padding: .2em .4em;
|
||||
margin: .8em 0 .2em;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,270 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using SteamWare;
|
||||
|
||||
namespace GMW.WebUserControls
|
||||
{
|
||||
public partial class mod_autocomplete : System.Web.UI.UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// evento valore selezionato
|
||||
/// </summary>
|
||||
public event EventHandler eh_valSelezionato;
|
||||
/// <summary>
|
||||
/// evento valore selezionato
|
||||
/// </summary>
|
||||
public event EventHandler eh_reset;
|
||||
/// <summary>
|
||||
/// segnaposto x casella testuale autocomplete
|
||||
/// </summary>
|
||||
public string placeholder { get; set; }
|
||||
|
||||
/// <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>
|
||||
/// caricamento pagina
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!Page.IsPostBack)
|
||||
{
|
||||
defaultVal = "";
|
||||
txtSelezione.Attributes["placeholder"] = placeholder;
|
||||
}
|
||||
}
|
||||
|
||||
protected void txtSelezione_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (txtSelezione.Text.Trim() == "")
|
||||
{
|
||||
hiddenFieldID.Text = defaultVal;
|
||||
_valore = defaultVal;
|
||||
if (eh_valSelezionato != null)
|
||||
{
|
||||
eh_valSelezionato(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <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 memLayer.ML.StringSessionObj(uid + "_sel");
|
||||
}
|
||||
set
|
||||
{
|
||||
memLayer.ML.setSessionVal(uid + "_sel", 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>
|
||||
/// 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 selezione
|
||||
{
|
||||
get
|
||||
{
|
||||
return txtSelezione.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
txtSelezione.Text = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// label dell'etichetta di ricerca
|
||||
/// </summary>
|
||||
public string labelRicerca
|
||||
{
|
||||
set
|
||||
{
|
||||
lblField.Text = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// num minimo caratteri x autocomplete
|
||||
/// </summary>
|
||||
public Int32 minCharAutocomplete
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(txtMinCharAutoCom.Text);
|
||||
}
|
||||
set
|
||||
{
|
||||
txtMinCharAutoCom.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// path del webservice (compreso metodo)
|
||||
/// nb: DI NORMA fornisce risultati nel formato label#valore
|
||||
/// </summary>
|
||||
public string ServicePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return txtServiceUrl.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
txtServiceUrl.Text = 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
|
||||
{
|
||||
txtSelezione.ToolTip = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// larghezza textbox in unità EM
|
||||
/// </summary>
|
||||
public int textEmWidht
|
||||
{
|
||||
set
|
||||
{
|
||||
txtSelezione.Width = Unit.Parse(string.Format("{0}em", value));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// larghezza textbox in unità %
|
||||
/// </summary>
|
||||
public int textEmPerc
|
||||
{
|
||||
set
|
||||
{
|
||||
txtSelezione.Width = Unit.Parse(string.Format("{0}%", value));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// imposta il focus sulla textBox
|
||||
/// </summary>
|
||||
public void setFocus()
|
||||
{
|
||||
txtSelezione.Focus();
|
||||
}
|
||||
/// <summary>
|
||||
/// permette di passare altri parametri di contesto al metodo invocato x autocomplete
|
||||
/// </summary>
|
||||
public string contextKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return txtSelezione.AccessKey;
|
||||
}
|
||||
set
|
||||
{
|
||||
txtSelezione.AccessKey = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// tabIndex del controllo
|
||||
/// </summary>
|
||||
public short TabIndex
|
||||
{
|
||||
set
|
||||
{
|
||||
txtSelezione.TabIndex = value;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// valore di default (x reset)
|
||||
/// </summary>
|
||||
public string defaultVal { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// effettuato reset
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
protected void lnkReset_Click(object sender, EventArgs e)
|
||||
{
|
||||
// resetto selezione e ricerca!
|
||||
txtSelezione.Text = "";
|
||||
hiddenFieldID.Text = defaultVal;
|
||||
_valore = defaultVal;
|
||||
if (eh_reset != null)
|
||||
{
|
||||
eh_reset(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace GMW.WebUserControls {
|
||||
|
||||
|
||||
public partial class mod_autocomplete {
|
||||
|
||||
/// <summary>
|
||||
/// BundleReference1 control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::Microsoft.AspNet.Web.Optimization.WebForms.BundleReference BundleReference1;
|
||||
|
||||
/// <summary>
|
||||
/// BundleReference2 control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::Microsoft.AspNet.Web.Optimization.WebForms.BundleReference BundleReference2;
|
||||
|
||||
/// <summary>
|
||||
/// lblField control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Label lblField;
|
||||
|
||||
/// <summary>
|
||||
/// btnPost control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Button btnPost;
|
||||
|
||||
/// <summary>
|
||||
/// txtSelezione control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.TextBox txtSelezione;
|
||||
|
||||
/// <summary>
|
||||
/// hiddenFieldID control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.TextBox hiddenFieldID;
|
||||
|
||||
/// <summary>
|
||||
/// txtMinCharAutoCom control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.TextBox txtMinCharAutoCom;
|
||||
|
||||
/// <summary>
|
||||
/// txtServiceUrl control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.TextBox txtServiceUrl;
|
||||
|
||||
/// <summary>
|
||||
/// lnkReset control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.LinkButton lnkReset;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user