SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: string problem

  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    string problem

    im building a link in my .net sode behind page to a javascript function.

    i need to pass a variable to this function.

    if i set my string without the parameter like

    Code:
    Dim reportLink As HyperLink
                    reportLink = New HyperLink
                    
                    reportLink.Text = "Map"
                    reportLink.ImageUrl = "images/thumbnails/map-icon.jpg"
                    
                    reportLink.Attributes.Add("onclick", "return openRadWindowFromGrid();")
                    
                    linkCell.Controls.Add(reportLink)
    this works ok in that the window is launched.

    however if i add my parameter variable with

    reportLink.Attributes.Add("onclick", "return openRadWindowFromGrid(" + UrlString + ");")

    the link doesnt trigger at all...

    whats the correct way to construct this string?

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by mark-web View Post
    whats the correct way to construct this string?
    It seems that the resulting string is unquoted. For example:
    return openRadWindowFromGrid(grid5)

    which would be treated as attempting to use a variable called grid5

    Quotes are required to let JavaScript know that it's a string, and not a variable instead.
    return openRadWindowFromGrid('grid5')
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •