簡體   English   中英

將用戶ID從處理程序發送到asp.net中的aspx頁面

[英]send userID from handler to aspx page in asp.net

我正在asp.net上工作。 我已使用處理程序應用了全文搜索功能。 現在,我希望當用戶從列表中選擇一個名稱時(在輸入關鍵字后建議),頁面應重定向到該人的個人資料。

<link href="Content/jquery.autocomplete.css" rel="stylesheet" />
<script src="Scripts/jquery-1.4.1.min.js"></script>
<script src="Scripts/jquery-1.3.2.min.js"></script>
<script src="Scripts/jquery.autocomplete.js"></script>
 <script type="text/javascript">
  $(document).ready(function () {
    $("#<%=txtSearch.ClientID%>").autocomplete('Search_CS.ashx');
});
 </script> 

<div>
    <asp:TextBox ID="txtSearch" runat="server" ></asp:TextBox>
</div>
<asp:Button ID="search" runat="server" Text="Search" OnClick="search_Click" />

當用戶在文本框中鍵入名稱時,它將返回帶有匹配搜索文本的用戶名。 在處理程序中處理(ashx文件)

public void ProcessRequest (HttpContext context) {
    string prefixText = context.Request.QueryString["q"];
    using (SqlConnection conn = new SqlConnection(strcon))
    {

        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.CommandText = "select Profile_ID,FirstName, LastName from UserProfile where FirstName like '%' + @SearchText + '%' OR LastName like '%' + @SearchText + '%'";

            cmd.Parameters.AddWithValue("@SearchText", prefixText);
            cmd.Connection = conn;
            StringBuilder sb = new StringBuilder();
            conn.Open();
            using (SqlDataReader sdr = cmd.ExecuteReader())
            {
                while (sdr.Read())
                {
                    sb.Append(sdr["FirstName"]).Append(" ").Append(sdr["LastName"]).Append(Environment.NewLine);

                }
            }
            conn.Close();
            context.Response.Write(sb.ToString());

        }
    }
}

現在,當用戶鍵入“ Tom”時,將打開一個列表,其中所有用戶的名稱均為“ tom”。 當用戶選擇“ Tom John”時,頁面應導航到Tom John個人資料。 如何將用戶重定向到特定用戶的個人資料頁面?

如何在search_Click中使用Server.Transfer或Response.Redirect方法?

您的問題的答案-如何為在自動完成中選擇的給定用戶獲取Profile_Id:

jQuery UI自動完成值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM