sistemati metodi accessori x selettore autocompletamento (manca aspetto grafico al limite...)

This commit is contained in:
Samuele Locatelli
2013-05-13 16:31:30 +02:00
parent c7911b2246
commit bb3bf601d0
9 changed files with 170 additions and 23 deletions
+1 -1
View File
@@ -26,5 +26,5 @@
</section>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<uc2:mod_autocomplete ID="mod_autocomplete1" runat="server" />
<uc2:mod_autocomplete ID="mod_autocomplete1" runat="server" ServicePath="/Services/WS_data.asmx/Test" minCharAutocomplete="3" contextKey="a" />
</asp:Content>
@@ -18,12 +18,6 @@ namespace PROJ_ETS.Services
public class WS_Data : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string[] test(string keywordStartsWith)
@@ -6,7 +6,7 @@
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Services/WS_data.asmx/Test",
url: "<%=txtServiceUrl.Text %>",
data: "{'keywordStartsWith':'" + request.term + "'}",
dataType: "json",
async: true,
@@ -29,8 +29,9 @@
$("#<%=txtSelezione.ClientID %>").val(i.item.label);
$("#<%=btnPost.ClientID %>").click();
},
minLength: 2
});
//minLength: 2
minLength: <%=txtMinCharAutoCom.Text %>
});
});
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
@@ -42,7 +43,7 @@
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Services/WS_data.asmx/Test",
url: "<%=txtServiceUrl.Text %>",
data: "{'keywordStartsWith':'" + request.term + "'}",
dataType: "json",
async: true,
@@ -61,20 +62,22 @@
});
},
select: function (e, i) {
$("#<%=hiddenFieldID.ClientID %>").val(i.item.val);
$("#<%=txtSelezione.ClientID %>").val(i.item.label);
$("#<%=btnPost.ClientID %>").click();
},
minLength: 2
$("#<%=hiddenFieldID.ClientID %>").val(i.item.val);
$("#<%=txtSelezione.ClientID %>").val(i.item.label);
$("#<%=btnPost.ClientID %>").click();
},
//minLength: 2
minLength: <%=txtMinCharAutoCom.Text %>
});
});
});
});
});
</script>
<label for="txtSelezione">Tags: </label>
<asp:Label runat="server" ID="lblField" for="txtSelezione" Text="Cerca:" AssociatedControlID="txtSelezione" />
<asp:TextBox runat="server" ID="hiddenFieldID" AutoPostBack="true" OnTextChanged="hiddenFieldID_TextChanged" Visible="true"
ViewStateMode="Enabled" Width="0em" Font-Size="6pt" BackColor="Transparent" BorderStyle="None" />
<asp:TextBox runat="server" ID="txtSelezione" CssClass="searchinput" OnTextChanged="txtSelezione_TextChanged" AutoPostBack="True" />
<asp:Button runat="server" ID="btnPost" OnClick="btnPost_Click" Visible="true" Text="..." />
<br />
<asp:Label runat="server" ID="lblVal" />
<asp:TextBox runat="server" ID="txtMinCharAutoCom" Text="2" Visible="false" />
<asp:TextBox runat="server" ID="txtServiceUrl" Text="/Services/WS_data.asmx/Test" Visible="false" />
@@ -39,7 +39,15 @@ namespace PROJ_ETS.WebUserControls
protected void txtSelezione_TextChanged(object sender, EventArgs e)
{
lblVal.Text = string.Format("Chiave:{0}, valore {1}", hiddenFieldID.Text, txtSelezione.Text);
if (txtSelezione.Text.Trim() == "")
{
hiddenFieldID.Text = "";
_valore = "";
if (eh_valSelezionato != null)
{
eh_valSelezionato(this, new EventArgs());
}
}
}
/// <summary>
@@ -82,5 +90,129 @@ namespace PROJ_ETS.WebUserControls
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 label
{
get
{
return txtSelezione.Text;
}
set
{
txtSelezione.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>
/// 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;
lblField.Text = string.Format("Cerca: ([{0}])", value);
}
}
/// <summary>
/// tabIndex del controllo
/// </summary>
public short TabIndex
{
set
{
txtSelezione.TabIndex = value;
}
}
}
}
@@ -12,6 +12,15 @@ namespace PROJ_ETS.WebUserControls {
public partial class mod_autocomplete {
/// <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>
/// hiddenFieldID control.
/// </summary>
@@ -40,12 +49,21 @@ namespace PROJ_ETS.WebUserControls {
protected global::System.Web.UI.WebControls.Button btnPost;
/// <summary>
/// lblVal control.
/// 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.Label lblVal;
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;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.