JavaScript syntax errors for creating new class


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: JavaScript syntax errors for creating new class

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Posts
    79

    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

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    I am not able to reproduce this behavior. Does your project include a reference to the Microsoft.VisualBasic namespace?

    Also, you might consider using the System.Text.StringBuilder class rather than string concatenation to build your JavaScript.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Aug 2005
    Posts
    79
    Thanks Phil.

    I used Environment.NewLine for the vbCrLf, and "" for Chr(34)

Similar Threads

  1. Handle errors with ASP & Javascript
    By Michael S Moore in forum ASP.NET
    Replies: 1
    Last Post: 10-01-2002, 04:00 AM
  2. Replies: 1
    Last Post: 06-05-2001, 06:12 AM
  3. How To Do It - Shared Class Variables Part III
    By Patrick Ireland in forum .NET
    Replies: 5
    Last Post: 05-10-2001, 06:19 PM
  4. How To Do It - Shared Class Variables Part II
    By Patrick Ireland in forum .NET
    Replies: 3
    Last Post: 04-26-2001, 02:50 AM
  5. Sample Sites.
    By Murray Foxcroft in forum Web
    Replies: 5
    Last Post: 11-02-2000, 02: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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center