I have a webform with an AutoCompleteExtender and it is not working if I set the ContextKey=Session Variable. It works just fine if I set ContextKey="7". Any ideas?
[WebMethod]public
string[] autoSuggestIndiv(string prefixText,
int count, string contextKey)
{
// Open the database connection
OdbcConnection cnx =
new OdbcConnection(ConfigurationManager.ConnectionStrings["ODBCDataConnectionString"].ConnectionString);
// Store connection in session variable for aspx access
cnx.Open();
// *sbowman 3/11/2009 - Added AND Retired=0
String command =
"SELECT Name,Individual_ID,Customer_ID FROM tblIndividuals " +
"WHERE Name LIKE '" + prefixText +
"%' AND (Customer_ID='" + contextKey +
"' OR Customer_ID IS NULL) AND Retired=0" +
"ORDER BY Name";
OdbcDataAdapter dap =
new OdbcDataAdapter();
dap.SelectCommand =
new
OdbcCommand(command, cnx);
DataTable result =
new DataTable();
dap.Fill(result);
cnx.Close();
string[] names =
new string[result.Rows.Count];
int i = 0;
// Cycle through the results and put them into the string[] return format.
foreach (DataRow j
in result.Rows)
{
String name = j.ItemArray[0].ToString();
// Don't allow slashes/dashes in the autosuggest box.
if (!(name.Contains("/") || name.Contains("-") || name.Contains("\\")))
{
names.SetValue(name, i);
i++;
}
// End if, don't include slashes or dashes in selection.
Fashionista0...
Member
16 Points
66 Posts
AutoCompleteExtender ContextKey not working with Session Variable
Apr 06, 2009 02:56 PM|LINK
I have a webform with an AutoCompleteExtender and it is not working if I set the ContextKey=Session Variable. It works just fine if I set ContextKey="7". Any ideas?
<
asp:TextBox ID="txtIndividualName" runat="server" AutoCompleteType="None"></asp:TextBox> <cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"MinimumPrefixLength="3"
CompletionInterval="100"
ServiceMethod="autoSuggestIndiv" ServicePath="WebService.asmx"
CompletionSetCount="12"
TargetControlID="txtIndividualName"
UseContextKey="true"
ContextKey="7"
>
</cc1:AutoCompleteExtender>
[WebMethod]public string[] autoSuggestIndiv(string prefixText, int count, string contextKey){
// Open the database connection OdbcConnection cnx = new OdbcConnection(ConfigurationManager.ConnectionStrings["ODBCDataConnectionString"].ConnectionString); // Store connection in session variable for aspx accesscnx.Open();
// *sbowman 3/11/2009 - Added AND Retired=0 String command = "SELECT Name,Individual_ID,Customer_ID FROM tblIndividuals " + "WHERE Name LIKE '" + prefixText + "%' AND (Customer_ID='" + contextKey + "' OR Customer_ID IS NULL) AND Retired=0" + "ORDER BY Name"; OdbcDataAdapter dap = new OdbcDataAdapter();dap.SelectCommand =
new OdbcCommand(command, cnx); DataTable result = new DataTable();dap.Fill(result);
cnx.Close();
string[] names = new string[result.Rows.Count]; int i = 0; // Cycle through the results and put them into the string[] return format. foreach (DataRow j in result.Rows){
String name = j.ItemArray[0].ToString(); // Don't allow slashes/dashes in the autosuggest box. if (!(name.Contains("/") || name.Contains("-") || name.Contains("\\"))){
names.SetValue(name, i);
i++;
}
// End if, don't include slashes or dashes in selection.}
// End cycle through the results. return names;}
// End autoSuggestIndivMetalAsp.Net
All-Star
112151 Points
18246 Posts
Moderator
Re: AutoCompleteExtender ContextKey not working with Session Variable
Apr 06, 2009 03:06 PM|LINK
How/where are you setting the contextKey to session variable?
Fashionista0...
Member
16 Points
66 Posts
Re: AutoCompleteExtender ContextKey not working with Session Variable
Apr 06, 2009 03:16 PM|LINK
Sorry, I pasted the wrong code before. Here's the session variable code:
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"MinimumPrefixLength="3"
CompletionInterval="100"
ServiceMethod="autoSuggestIndiv" ServicePath="WebService.asmx"
CompletionSetCount="12"
TargetControlID="txtIndividualName"
UseContextKey="true"
ContextKey='<%# Session["customerID"].ToString() %>'
>
</cc1:AutoCompleteExtender>
BTW, the line
ContextKey='<%# Session["customerID"].ToString() %>' works perfectly on another page within the same project.
MetalAsp.Net
All-Star
112151 Points
18246 Posts
Moderator
Re: AutoCompleteExtender ContextKey not working with Session Variable
Apr 06, 2009 03:32 PM|LINK
How about setting the contextKey attribute in the code behind?
Fashionista0...
Member
16 Points
66 Posts
Re: AutoCompleteExtender ContextKey not working with Session Variable
Apr 06, 2009 03:45 PM|LINK
TY! It works perfectly now. That was really bugging me [<:o)]
dagamshiva
Member
71 Points
110 Posts
Re: AutoCompleteExtender ContextKey not working with Session Variable
Apr 10, 2009 04:44 AM|LINK
Hi write like this
[System.Web.Services.
WebMethod(EnableSession = true)]public string[] autoSuggestIndiv(string prefixText, int count, string contextKey)
{
//your coding
}
Hallelujahg
Member
3 Points
28 Posts
Re: AutoCompleteExtender ContextKey not working with Session Variable
Sep 14, 2010 09:08 PM|LINK
what is the solution for this bug?
What should be written in codebehind?