在 vb.net 中使用 jquery UI 自动完成文本框
我在表单中使用 jQuery 使用两个自动完成扩展器。我想将一个自动完成扩展器的值传递给另一个自动完成扩展器。请让我知道如何使用 jQuery 传递值。
我的 VB.net 页面:-
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="VB.aspx.vb" Inherits="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="jquery/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="jquery/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="jquery/jquery.autocomplete.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#txtSearch").autocomplete('Search_Scheme.ashx');
});
$(document).ready(function() {
$("#txtProperty").autocomplete('Search_Property.ashx');
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellspacing="0" cellpadding="0" align="center" border="0" style="text-align: left" width="95%">
<tr>
<td align="center" bgColor="#ffffff" style="width: 50%;">
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
</td>
<td align="center" bgColor="#ffffff" style="width: 50%;">
<asp:TextBox ID="txtProperty" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
我的 txtSearch 文本框类:-
<%@ WebHandler Language="VB" Class="Search_Scheme" %>
Imports System
Imports System.Web
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Imports System.Data
Imports System.Collections
Imports System.Collections.Generic
Imports System.Web.Script.Services
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.OleDb
Public Class Search_Scheme : Implements IHttpHandler
Implements SessionState.IRequiresSessionState
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim SQL As String = ""
Dim Con As New DbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim prefixText As String = context.Request.QueryString("q")
Dim sb As StringBuilder = New StringBuilder
SQL = " Select Scheme_Name,Scheme_Id from Scheme_Definition" & _
" Where Org_Id ='" & context.Session("OrgId") & "'"
If prefixText <> "" Then
SQL &= " and upper(scheme_Name) like '%" & prefixText.Trim().ToUpper().Replace("'", "''") & "%'"
End If
SQL &= " Order By Scheme_Name"
Con.Connect()
cmd = New OleDbCommand(SQL, Con.Con)
dr = cmd.ExecuteReader()
While dr.Read()
sb.Append(dr("Scheme_Name")) _
.Append(Environment.NewLine)
End While
dr.Close()
cmd.Cancel()
cmd.Dispose()
Con.DisConnect()
context.Response.Write(sb.ToString)
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
我的 txtProperty 文本框类:-
<%@ WebHandler Language="VB" Class="Search_Property" %>
Imports System
Imports System.Web
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Imports System.Data
Imports System.Collections
Imports System.Collections.Generic
Imports System.Web.Script.Services
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.OleDb
Public Class Search_Property : Implements IHttpHandler
Implements SessionState.IRequiresSessionState
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim SQL As String = ""
Dim Con As New DbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Con.Connect()
Dim prefixText As String = context.Request.QueryString("q")
Dim sb As StringBuilder = New StringBuilder
Dim tSchemeId As Integer = 0
Dim myString As String = System.Web.HttpContext.Current.Request.QueryString("country")
SQL = " SELECT SCHEME_ID FROM SCHEME_DEFINITION" & _
" WHERE ORG_ID ='" & context.Session("OrgId") & "'" & _
" AND UPPER(SCHEME_NAME) ='---Here text of txtSearch textBox----'"
'---Here i am not able to pass either scheme_id or scheme_name--- Please Help....
cmd = New OleDbCommand(SQL, Con.Con)
tSchemeId = CInt(cmd.ExecuteScalar())
cmd.Cancel()
cmd.Dispose()
'tSchemeId = 8
SQL = " SELECT PROPERTY_ID as PROPERTY_ID,PROPERTY_NAME" & _
" FROM PROPERTIES" & _
" WHERE SCHEME_ID ='" & tSchemeId & "'" & _
" ORDER BY PROPERTY_NAME"
'MsgBox(SQL)
cmd = New OleDbCommand(SQL, Con.Con)
dr = cmd.ExecuteReader()
While dr.Read()
sb.Append(dr("PROPERTY_NAME")) _
.Append(Environment.NewLine)
End While
dr.Close()
cmd.Cancel()
cmd.Dispose()
Con.DisConnect()
context.Response.Write(sb.ToString)
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
I am using two autocomplete extenders in my form using jQuery. I want to pass the value of one autocomplete extender to another autocomplete extender. Please let me know how can I pass value using jQuery.
My VB.net page :-
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="VB.aspx.vb" Inherits="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="jquery/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="jquery/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="jquery/jquery.autocomplete.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#txtSearch").autocomplete('Search_Scheme.ashx');
});
$(document).ready(function() {
$("#txtProperty").autocomplete('Search_Property.ashx');
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellspacing="0" cellpadding="0" align="center" border="0" style="text-align: left" width="95%">
<tr>
<td align="center" bgColor="#ffffff" style="width: 50%;">
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
</td>
<td align="center" bgColor="#ffffff" style="width: 50%;">
<asp:TextBox ID="txtProperty" runat="server"></asp:TextBox>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
My Class for txtSearch textbox:-
<%@ WebHandler Language="VB" Class="Search_Scheme" %>
Imports System
Imports System.Web
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Imports System.Data
Imports System.Collections
Imports System.Collections.Generic
Imports System.Web.Script.Services
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.OleDb
Public Class Search_Scheme : Implements IHttpHandler
Implements SessionState.IRequiresSessionState
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim SQL As String = ""
Dim Con As New DbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim prefixText As String = context.Request.QueryString("q")
Dim sb As StringBuilder = New StringBuilder
SQL = " Select Scheme_Name,Scheme_Id from Scheme_Definition" & _
" Where Org_Id ='" & context.Session("OrgId") & "'"
If prefixText <> "" Then
SQL &= " and upper(scheme_Name) like '%" & prefixText.Trim().ToUpper().Replace("'", "''") & "%'"
End If
SQL &= " Order By Scheme_Name"
Con.Connect()
cmd = New OleDbCommand(SQL, Con.Con)
dr = cmd.ExecuteReader()
While dr.Read()
sb.Append(dr("Scheme_Name")) _
.Append(Environment.NewLine)
End While
dr.Close()
cmd.Cancel()
cmd.Dispose()
Con.DisConnect()
context.Response.Write(sb.ToString)
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
My Class for txtProperty textbox:-
<%@ WebHandler Language="VB" Class="Search_Property" %>
Imports System
Imports System.Web
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Text
Imports System.Data
Imports System.Collections
Imports System.Collections.Generic
Imports System.Web.Script.Services
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data.OleDb
Public Class Search_Property : Implements IHttpHandler
Implements SessionState.IRequiresSessionState
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim SQL As String = ""
Dim Con As New DbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Con.Connect()
Dim prefixText As String = context.Request.QueryString("q")
Dim sb As StringBuilder = New StringBuilder
Dim tSchemeId As Integer = 0
Dim myString As String = System.Web.HttpContext.Current.Request.QueryString("country")
SQL = " SELECT SCHEME_ID FROM SCHEME_DEFINITION" & _
" WHERE ORG_ID ='" & context.Session("OrgId") & "'" & _
" AND UPPER(SCHEME_NAME) ='---Here text of txtSearch textBox----'"
'---Here i am not able to pass either scheme_id or scheme_name--- Please Help....
cmd = New OleDbCommand(SQL, Con.Con)
tSchemeId = CInt(cmd.ExecuteScalar())
cmd.Cancel()
cmd.Dispose()
'tSchemeId = 8
SQL = " SELECT PROPERTY_ID as PROPERTY_ID,PROPERTY_NAME" & _
" FROM PROPERTIES" & _
" WHERE SCHEME_ID ='" & tSchemeId & "'" & _
" ORDER BY PROPERTY_NAME"
'MsgBox(SQL)
cmd = New OleDbCommand(SQL, Con.Con)
dr = cmd.ExecuteReader()
While dr.Read()
sb.Append(dr("PROPERTY_NAME")) _
.Append(Environment.NewLine)
End While
dr.Close()
cmd.Cancel()
cmd.Dispose()
Con.DisConnect()
context.Response.Write(sb.ToString)
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要设置 extraParam 选项,如下所示:
请参阅:
http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions
如果您需要级联值,则必须在父级上设置一个选择处理程序,以将所选值存储在闭包中或页面上的某个位置。 (除非该值是用户输入/选择的值,在这种情况下您可以从那里获取它。)
U
You want to set the extraParam option, as in:
see:
http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions
If you need the values to be cascading, you'll have to set a select handler on the parent to store the selected value in a closure or somewhere on the page. (unless the value is what the user typed/selected, in which case you can just grab it from there.)
U