Click here to Skip to main content
15,921,697 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

i have an issue like i have one autocomplete extender inside update panel .I am setting context key from client side.but when reaching server side at some point context key is becoming null

my code:

C#
<script>
 function SetContextKey() {
            debugger
            if (($('#<%=ddl.ClientID %> option:selected').text()) == "Select") {
                alert("Select Branch");
                return;
            }
            $find('<%=AutoCompleteExtender1.ClientID%>').set_contextKey($('#<%=ddl.ClientID %> option:selected').text());
        }

</script>


html 

<asp:UpdatePanel ID=UpdatePanel1runat=server>
 <asp:TextBox ID="txt" runat="server" onkeyup="SetContextKey()"  placeholder="Type in first two letters" Width="201px" AutoPostBack="True">
                            <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServiceMethod="AutoCompleteBranch"
                                ServicePath="abc.asmx" MinimumPrefixLength="2" CompletionInterval="100"
                                EnableCaching="False" UseContextKey="True" TargetControlID="txt" DelimiterCharacters=""
                                Enabled="True">



server side

C#
[WebMethod]
  public  string[] AutoCompleteBranch(string prefixText, int count, string contextKey)
  {
      List<string> ajaxDataCollection = new List<string>();

      //_objCommonBO = new CommonBO();
      //_objCommonBL = new CommonBL();
      //_objCommonBO.BranchName = prefixText;
      DataTable dt = new DataTable();
      SqlDataAdapter da = new SqlDataAdapter("SP", con);
      da.SelectCommand.CommandType = CommandType.StoredProcedure;

      da.SelectCommand.Parameters.AddWithValue("@b", prefixText);
      da.SelectCommand.Parameters.AddWithValue("@ba", contextKey);

      dt.Clear();
      da.Fill(dt);

      if (dt.Rows.Count > 0)
      {
          for (int i = 0; i < dt.Rows.Count; i++)
          {
              ajaxDataCollection.Add(dt.Rows[i]["BR"].ToString());
          }
      }

      return ajaxDataCollection.ToArray();
   }


I am getting context key value here but after reaching
C#
da.Fill(dt);

contextkey is becoming null and am getting error from stored procedure


pls help

What I have tried:

tried using static function but not working
Posted
Updated 5-May-16 3:18am
v3
Comments
Karthik_Mahalingam 4-May-16 8:06am    
why you are doing that in keyup event?
priyadarshini tv 5-May-16 0:02am    
in that keyup event am calling that javascript function setcontext key
Karthik_Mahalingam 5-May-16 0:05am    
when you enter some text it will search the text, its default functionality, on top of that y you want to use keyup..
priyadarshini tv 5-May-16 0:22am    
Please see what setcontextkey function is doing.On keyup event of the textbox it is passing a dropdown value to server side.This dropdown value is supposed to pass as value for parameteer @ba..but it is becoming null.Nothing is doing with textbox value because it will search for the text like you said.
Karthik_Mahalingam 5-May-16 0:25am    
try hardcoding the value
set_contextKey('sometext');
and see whether you are getting are not ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900