Javascript on Context Menu Click

3 posts, 1 answers
  1. TPerry
    TPerry avatar
    47 posts
    Member since:
    Jul 2006

    Posted 10 Feb 2009 Link to this post

    I have a RadGrid with a ContextMenu appearing when you right click.  When you click on an item in the context menu, I want to open a new window using Javascript.  I get into the ItemClick sub on the menu, but my Javascript is not firing.  I'm certain that I have something wrong in the RegisterStartupScript line.  I even think it's my first parameter.  What should go there?  The grid is ajaxed, so there's no postback, I tried the name of the menu as well.  Help?

    Dim

     

    strScript As String = ""

     

    strScript =

    "<script type='text/javascript'>window.open('http://www.google.com'); </script>"

     

    ScriptManager.RegisterStartupScript(GridFees,

    Me.GetType(), "myKey", strScript, True)

     

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 Feb 2009 Link to this post

    Hi,

    Try the following code snippet and check whether it's working for you.

    CS:
    Protected Sub RadContextMenu1_ItemClick(ByVal sender As ObjectByVal e As RadMenuEventArgs)  
         If e.Item.Text = "OpenWindow" Then 
             Dim strScript As String = "<script type='text/javascript'>" 
             strScript += "window.open('http://www.google.com');" 
             strScript += "</script>" 
             ScriptManager.RegisterStartupScript(Me.Page, Me.[GetType](), "myKey", strScript, False)  
         End If 
    End Sub 

    Thanks,
    Princy.
  3. TPerry
    TPerry avatar
    47 posts
    Member since:
    Jul 2006

    Posted 12 Feb 2009 Link to this post

    That was it!  Thank you so much!
Back to Top