-
JavaScript syntax errors for creating new class
My basic goal is to add autocomplet to a dropdownlist.
Here's my class below with which I'm having issues.
On the Protected Overrides Sub OnLoad routine, I keep getting the syntax errors (blue underlining) for chr(34) and for vbCrLf. The indicators say "Not Declared"
Imports System
Imports System.Web.UI.WebControls
Namespace Thycotic.Web.UI.WebControls
Public Class KeySortDropDownList
Inherits DropDownList
Private Shared functionName As String = "KeySortDropDownList_onkeypress"
Private _caseSensitiveKeySort As Boolean = False
Public Overridable Property CaseSensitiveKeySort() As Boolean
Get
Return _caseSensitiveKeySort
End Get
Set(ByVal Value As Boolean)
_caseSensitiveKeySort = Value
End Set
End Property
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e) ' call the base class method
' define the client-side script
Dim script As String
script = "<script language=" & Chr(34) & "javascript" & Chr(34) & " type=" & Chr(34) & "text/javascript" & Chr(34) & ">" & vbCrLf
script &= "function " & functionName & " (dropdownlist,caseSensitive) {" & vbCrLf
script &= " // check the keypressBuffer attribute is defined on the dropdownlist" & vbCrLf
script &= " var undefined; " & vbCrLf
script &= " if (dropdownlist.keypressBuffer == undefined) { " & vbCrLf
script &= " dropdownlist.keypressBuffer = ''; " & vbCrLf
script &= " } " & vbCrLf
script &= " // get the key that was pressed " & vbCrLf
script &= " var key = String.fromCharCode(window.event.keyCode); " & vbCrLf
script &= " dropdownlist.keypressBuffer += key;" & vbCrLf
script &= " if (!caseSensitive) {" & vbCrLf
script &= " // convert buffer to lowercase" & vbCrLf
script &= " dropdownlist.keypressBuffer = dropdownlist.keypressBuffer.toLowerCase();" & vbCrLf
script &= " }" & vbCrLf
script &= " // find if it is the start of any of the options " & vbCrLf
script &= " var optionsLength = dropdownlist.options.length; " & vbCrLf
script &= " for (var n=0; n < optionsLength; n++) { " & vbCrLf
script &= " var optionText = dropdownlist.options[n].text; " & vbCrLf
script &= " if (!caseSensitive) {" & vbCrLf
script &= " optionText = optionText.toLowerCase();" & vbCrLf
script &= " }" & vbCrLf
script &= " if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0) { " & vbCrLf
script &= " dropdownlist.selectedIndex = n; " & vbCrLf
script &= " return false; // cancel the default behavior since " & vbCrLf
script &= " // we have selected our own value " & vbCrLf
script &= " } " & vbCrLf
script &= " } " & vbCrLf
script &= " // reset initial key to be inline with default behavior " & vbCrLf
script &= " dropdownlist.keypressBuffer = key; " & vbCrLf
script &= " return true; // give default behavior " & vbCrLf
script &= "} " & vbCrLf
script &= "</script>"
' register the client-side script block
Me.Page.RegisterClientScriptBlock(functionName, script) '
' add to the onkeypress event
Me.Attributes.Add("onkeypress", "return " + functionName + "(this," + _caseSensitiveKeySort.ToString().ToLower() + ")")
End Sub 'OnLoad
End Class 'KeySortDropDownList
End Namespace 'Thycotic.Web.UI.WebControls
Similar Threads
-
By Michael S Moore in forum ASP.NET
Replies: 1
Last Post: 10-01-2002, 04:00 AM
-
By Fred Mayes in forum Java
Replies: 1
Last Post: 06-05-2001, 06:12 AM
-
By Patrick Ireland in forum .NET
Replies: 5
Last Post: 05-10-2001, 06:19 PM
-
By Patrick Ireland in forum .NET
Replies: 3
Last Post: 04-26-2001, 02:50 AM
-
By Murray Foxcroft in forum Web
Replies: 5
Last Post: 11-02-2000, 03:42 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|