在了解了自动完成属性之后 -ContextKey
我将其用作优势:
每个扩展器对象的数据源将由相同的 WebMethod 处理。
就其本身而言,这对我来说是一个成就。
既然每件事都非常完美,那么问题是:
我需要传递另一个参数,当第二个文本框发送对 AutoComplete-Datasource 的请求时,就在 stage = table was selected 之后。
所以现在我不仅需要硬编码/常量,还需要所选表的值。
这实际上是 的值#TBX_TableSelectorFirstStage
,以及硬编码的ContextKey
值......
(类似ContextKey += value of TBX_TableSelectorFirstStage
)
这样我就可以通过请求的表(表的名称)绘制指定的列列表
这是Jquery
代码
<script type="text/javascript">
$('document').ready(function () {
var IvalidValue_Msg = "table was not selected";
var TBX_tables = $(this);
var TBX_Columns = $('#TBX_ColumnsSelectorFirstStage');
$('#TBX_TableSelectorFirstStage')
.val("Choose a Table")
.focus(function () {
$(this).val("");
$(this).attr("dir", "ltr");
}).blur(function () {
var TBXTablsVALUE = $('#TBX_TableSelectorFirstStage').val();
var Lngth = $('#TBX_TableSelectorFirstStage').val().length;
var InvalidTBXBlur_TablesValue = TBXTablsVALUE == "" || TBXTablsVALUE == " " || Lngth < 4;
if (InvalidTBXBlur_TablesValue) {
$(this).focus();
$(this).val(IvalidValue_Msg);
}
else {
$(TBX_Columns).focus();
SetContextKeyValue();
}
//$(this).next(':input').focus();
}).change(function () {
var TBXTablsVALUE = $('#TBX_TableSelectorFirstStage').val();
var Lngth = $('#TBX_TableSelectorFirstStage').val().length;
var InvalidTBXBlur_TablesValue = TBXTablsVALUE == "" || TBXTablsVALUE == " " || Lngth < 4;
if (InvalidTableValue) {
$(this).val(IvalidValue_Msg);
}
else {
SetContextKeyValue();
}
}).click(function () {
$(this).val("");
});
});
/// ==========================================================\\\
///Jquery Section That Is Suppose To manipulate contextKey Property.
function SetContextKeyValue() {
// var ttt = $get('AjaxAcEx_Columns_FirstStage',
alert("asasas");
// var x = $('#AutoCompleteExtender3'); //.set_contextKey($get('AjaxAcEx_Tables_FirstStage').value);
alert($('#AjaxAcEx_Columns_FirstStage').attr("id"));
}
这是ASPX 代码
<form id="form1" runat="server">
<cc1:ToolkitScriptManager ID="ToolKitScrptMan1" runat="server"></cc1:ToolkitScriptManager>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" TargetControlID="TBX_FntsAC" runat="server"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="100"
ServiceMethod="MyAcReqHandler" ContextKey="acFontsRquest"
FirstRowSelected="true" CompletionListCssClass="CL_Css_DataBase" CompletionListItemCssClass="CL_ItemCss_DataBase" CompletionListHighlightedItemCssClass="CL_tHighlightedItemCss_DataBase">
</cc1:AutoCompleteExtender>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender2" BehaviorID="AjaxAcEx_Tables_FirstStage" TargetControlID="TBX_TableSelectorFirstStage" runat="server"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="100"
ServiceMethod="MyAcReqHandler" ContextKey="acTablesSelector_FirstStage"
FirstRowSelected="true" CompletionListCssClass="CL_Css_DataBase" CompletionListItemCssClass="CL_ItemCss_DataBase" CompletionListHighlightedItemCssClass="CL_tHighlightedItemCss_DataBase">
</cc1:AutoCompleteExtender>
<%-- Here is where i am stuck .
object /element - AutoCompleteExtender3 / BehaviorID AjaxAcEx_Columns_FirstStage
This is the object i need to Set it's ContextKey attribute-value,
with the result value of #TBX_TableSelectorFirstStage
--%>
<cc1:AutoCompleteExtender ID="AutoCompleteExtender3" BehaviorID="AjaxAcEx_Columns_FirstStage" TargetControlID="TBX_ColumnsSelectorFirstSTage" runat="server"
MinimumPrefixLength="1" EnableCaching="true" CompletionSetCount="1" CompletionInterval="100"
ServiceMethod="MyAcReqHandler" ContextKey="acColumnsSelector_FirstStage"
FirstRowSelected="true" CompletionListCssClass="CL_Css_DataBase" CompletionListItemCssClass="CL_ItemCss_DataBase" CompletionListHighlightedItemCssClass="CL_tHighlightedItemCss_DataBase">
</cc1:AutoCompleteExtender>
<div id="Div_firstStage" runat="server" style="width:90%" dir="rtl">
<asp:TextBox ID="TBX_TableSelectorFirstStage" runat="server" />
<asp:TextBox ID="TBX_ColumnsSelectorFirstStage" runat="server" />
</div>
* .Cs 代码背后* (webMethod)
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod(EnableSession = true)]
public static List<string> MyAcReqHandler(string prefixText, string contextKey)
{
List<string> retListAC = new List<string>();
switch (contextKey)
{
case AutoComplete.Param.acTablesSelector_FirstStage:
retListAC = GetListForAutoComplete<HTDB_Tables>(App.VarNms.SesDbTablsList);
break;
case AutoComplete.Param.acColumnsSelector_FirstStage:
retListAC = GetListForAutoComplete<HTDB_Cols>(App.VarNms.SesDbTablsList);
break;
case AutoComplete.Param.acFontsRquest_SecondStage:
retListAC = GetListForAutoComplete<fntNams>(App.VarNms.SesFontsList);
break;
}
return AutoComplete.FromListStr(prefixText, retListAC);
}
private static List<string> GetListForAutoComplete<TheClassNameHere>(string SessionVarName, string NestedClassName="")
{
List<string> ReturnedList = new List<string>();
if (CurrSesVarSet.SesVar_AcDsListStr.Count == 0)
{
bool isNested = typeof(TheClassNameHere).IsNested;
switch (isNested)
{
case true:
ReturnedList = RflectMeths.anyNestedClassFldsAsListByType<TheClassNameHere>(NestedClassName);
break;
default:
ReturnedList = RflectMeths.anyClassFldsAsListByType<TheClassNameHere>();
break;
}
CurrSesVarSet.SesVar_AcDsListStr = ReturnedList;
CurrentSession.AddVar(SessionVarName, ReturnedList);
}
else
if (CurSessionMesthods.VarExistStat(App.VarNms.SesFontsList))
ReturnedList = CurSessionMesthods.GetSessionVar.AsListStr(SessionVarName);
else ReturnedList = CurrSesVarSet.SesVar_AcDsListStr;
return ReturnedList;
}
由于此应用程序中的一项努力是避免完全回发,因此我想实现-设置ContextKey
, via Jquery
, ...除非我的基本假设有误,否则通过 c# 执行此操作-后面的代码将导致整页回发,所以如果它在没有重新加载页面的情况下完成,只要我能发送这个参数,我就不在乎了,因为直到现在我一直保持着类似桌面的用户体验(;
感谢您的帮助,解决这个问题将不胜感激!