Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 677
  • Last Modified:

VisualASP: Passing QueryString for oncontextmenu Function

Greetings,

A form is reading and presenting tree data from SQL Server, and Treeview.QueryString and Node.URL are handling navigation well.  

However, I cannot get the right-click to navigate to an URL with existing QueryString data appended.

-------------------------------------------------------------
I suspect that I can pass information as needed by altering the following calls (within the TreeView code presented below) :

TreeView.NavDHTML = "oncontextmenu=ContextMenu('#TVK#')"
Node.DHTML = "oncontextmenu=ContextMenu('#TVK#')"

where #TVK# is nodekey, #TVI# is index, #QUERYSTRING# is just that, etc are expanded by the object.  Or can we build and pass a string by concat'ing var=value pairs.

-------------------------------------------------------------
The VisualASP Sample for the ContextMenu function:

function ContextMenu(nNodeKey) {
      MenuIsOn = "Y"
      document.getElementById("tv_context_text").innerHTML = 'Node Selected: ' + nNodeKey;

      if (document.all)      
      // add your URLs Here for the context menu items as this adds the nodes key as a querystring.
      document.all.tv_context_1.href = "?NodeKey=" + nNodeKey
      document.all.tv_context_2.href = "?NodeKey=" + nNodeKey
      document.all.tv_context_3.href = "?NodeKey=" + nNodeKey
      document.all.tv_context_4.href = "?NodeKey=" + nNodeKey
      document.all.tv_context_5.href = "?NodeKey=" + nNodeKey
      document.all.tv_context_6.href = "?NodeKey=" + nNodeKey
      document.oncontextmenu =showMenu;
      if (document.layers) {
      // add your URLs Here for the context menu items as this adds the nodes key as a querystring.
      document.tv_context_1.href = "?NodeKey=" + nNodeKey
      document.tv_context_2.href = "?NodeKey=" + nNodeKey
      document.tv_context_3.href = "?NodeKey=" + nNodeKey
      document.tv_context_4.href = "?NodeKey=" + nNodeKey
      document.tv_context_5.href = "?NodeKey=" + nNodeKey
      document.tv_context_6.href = "?NodeKey=" + nNodeKey
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = showMenu;
      }
}
</script>

-------------------------------------------------------------
Our TreeView code follows:

<%

' Create the Component
Set TreeView = Server.CreateObject("VASPTV.ASPTreeView")

TreeView.LicenseKey = "blah-blah-blah" ' enter a valid license key to license the component.
TreeView.Class = "TreeView" ' class name in visualasp.css file
TreeView.ImagePath = "/resources/treeview" ' image path where the images are located
TreeView.LineStyle = 1 ' LineStyle=RootLines
TreelinesPlusMinusPictureText = 7
TreeView.Style = 7 ' Style=TreelinesPlusMinusPicureText
TreeView.ExpandAll = False

' ################################################################################################
TreeView.QueryString = "process_desc=" & Request.QueryString("process_desc") & "&lookup_type_desc=" & Request.QueryString("lookup_type_desc") & "&view_by_identifier=" & Request.QueryString("view_by_identifier")
' ################################################################################################

' ######################################################
' adds the oncontextmenu event on the +/- links
TreeView.NavDHTML = "oncontextmenu=ContextMenu('#TVK#')"
' ######################################################

Do While Not ap_doc_group_control__tree.EOF
      
      If ap_doc_group_control__tree("Parent") & "" = "" Then ' Root Node
            Set Node = TreeView.Nodes.Add(,,cstr(ap_doc_group_control__tree("Key")))
      Else
            Set Node = TreeView.Nodes.Add(cstr(ap_doc_group_control__tree("Parent")),4,cstr(ap_doc_group_control__tree("Key")))
      End If

      Node.Text = ap_doc_group_control__tree("Text") & ""
      Node.ForeColor = ap_doc_group_control__tree("ForeColor") & ""
      Node.Image = ap_doc_group_control__tree("Image") & ""
      Node.ExpandedImage = ap_doc_group_control__tree("ExpandedImage") & ""
      Node.Bold = ap_doc_group_control__tree("Bold")
      Node.URL = ap_doc_group_control__tree("URL")  & "?process_desc=" & Request.QueryString("process_desc") & "&lookup_type_desc=" & Request.QueryString("lookup_type_desc") & "&view_by_identifier=" & Request.QueryString("view_by_identifier") & "&doc_group_id=" & ap_doc_group_control__tree("doc_group_id")  & "&doc_id=" & ap_doc_group_control__tree("doc_id") & "&Node=" & Request.QueryString("Node") & "&sNode=" & Request.QueryString("sNode") & "&Exp=" & Request.QueryString("Exp")
' ########################################################
' adds the oncontextmenu event on the node and image links
      Node.DHTML = "oncontextmenu=ContextMenu('#TVK#')"
' ########################################################
      
      ap_doc_group_control__tree.MoveNext
      
Loop

' Display the TreeView
TreeView.Show

' Destroy the Component
TreeView.Unload
Set TreeView = Nothing

%>

Thanks for any support or feedback in advance.

Jahlife
DBA/Developer
0
jahlife
Asked:
jahlife
  • 5
  • 4
1 Solution
 
davidlars99Commented:
I don't like the way that this code is generated let's change that and will continue from there, I mean it's missing ";" characters all aver...
it not a good practice... trust me I had problems with none proper use of ";" char..

function ContextMenu(nNodeKey) {
     MenuIsOn = "Y"                                                                                                                       //here
     document.getElementById("tv_context_text").innerHTML = 'Node Selected: ' + nNodeKey;

     if (document.all)    
     // add your URLs Here for the context menu items as this adds the nodes key as a querystring.
     document.all.tv_context_1.href = "?NodeKey=" + nNodeKey                                                          //here
     document.all.tv_context_2.href = "?NodeKey=" + nNodeKey                                                          //here and everywhere to the end
     document.all.tv_context_3.href = "?NodeKey=" + nNodeKey
     document.all.tv_context_4.href = "?NodeKey=" + nNodeKey
     document.all.tv_context_5.href = "?NodeKey=" + nNodeKey
     document.all.tv_context_6.href = "?NodeKey=" + nNodeKey
     document.oncontextmenu =showMenu;
     if (document.layers) {
     // add your URLs Here for the context menu items as this adds the nodes key as a querystring.
     document.tv_context_1.href = "?NodeKey=" + nNodeKey
     document.tv_context_2.href = "?NodeKey=" + nNodeKey
     document.tv_context_3.href = "?NodeKey=" + nNodeKey
     document.tv_context_4.href = "?NodeKey=" + nNodeKey
     document.tv_context_5.href = "?NodeKey=" + nNodeKey
     document.tv_context_6.href = "?NodeKey=" + nNodeKey
     document.captureEvents(Event.MOUSEDOWN);
     document.onmousedown = showMenu;
     }
}


cheers!
 dave
0
 
jahlifeAuthor Commented:
Dave,

Thanks for responding, I agree.  I will review and edit the VisualASP code, particularly the javascript, that I am including from the vendor samples.  It might be that 'syntax' was contributing to resulting errors when attempting to process parameters in the ContextMenu function.  I am more SQL and VB aware, thanks for pointing out the basics.

Thanks,
Jahlife
0
 
davidlars99Commented:
when you come back make sure you post all error messages and other  problems
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jahlifeAuthor Commented:
Dave,

The code that is posted above does not produce errors within the ASP page.  

As I tried to implement additional parameters in the call to the ContextMenu function, I introduced errors.  I can post the entire page or a internet URL for review if this would help.

I am presently cleaning up the code by adding ";", as recommended.

Thanks,
Jahlife
0
 
davidlars99Commented:
yeah, that would be perfect. Let me see the entire generated page
0
 
jahlifeAuthor Commented:
Dave,

Thanks for your interest.  This adapted code from VisualASP can be viewed on http://training.tellvisor.com/ and you can impersonate an existing demo user using these credentials:

username = ola
password = password

After signing on, click on "Content Explorer".  This is the initial form that is displaying the VisualASP TreeView object.  

As you expand, say the Intranet Site folder area, the tree can navigate OK.  And if you right-click a node, you can trigger the ContextMenu.  This level of code is the sample from the vendor, as posted here with addition of ";" to javascript section.

To reiterate, my goal is to allow the right-click to be able to invoke another .asp page passing the existing querystring data.  Similar to how the tree is navigating now, I just need to direct to a different .asp file, any will do for now.

If you right-click now, we go to same .asp page and lost querystring data.

My level of knowledge is lower on javascript, and I have interpreted that I need to be able to pass this information to the ContextMenu, but I may be entirely off track here.  Let me know how I can help better present my problem.

Thanks again,
Jahlife
0
 
davidlars99Commented:
ok,
I hope this is what you need?

I added   -- (url)?url:"?NodeKey=" + nNodeKey;--   if you pass the proper url from --ContextMenu(1,escape(this.href))--  like this or

 --ContextMenu(1,escape(this.HREF))--  I don't see a reason why this shouldn't work





function ContextMenu(nNodeKey, url) {
      MenuIsOn = "Y";
      document.getElementById("tv_context_text").innerHTML = 'Node Selected: ' + nNodeKey;

      if (document.all)      
      // add your URLs Here for the context menu items as this adds the nodes key as a querystring.
      document.all.tv_context_1.href = (url)?url:"?NodeKey=" + nNodeKey;
      document.all.tv_context_2.href = (url)?url:"?NodeKey=" + nNodeKey;
      document.all.tv_context_3.href = (url)?url:"?NodeKey=" + nNodeKey;
      document.all.tv_context_4.href = (url)?url:"?NodeKey=" + nNodeKey;
      document.all.tv_context_5.href = (url)?url:"?NodeKey=" + nNodeKey;
      document.all.tv_context_6.href = (url)?url:"?NodeKey=" + nNodeKey;
      document.oncontextmenu =showMenu;
      if (document.layers) {
      // add your URLs Here for the context menu items as this adds the nodes key as a querystring.
      document.tv_context_1.href = (url)?url:"?NodeKey=" + nNodeKey;
      document.tv_context_2.href = (url)?url:"?NodeKey=" + nNodeKey;
      document.tv_context_3.href = (url)?url:"?NodeKey=" + nNodeKey;
      document.tv_context_4.href = (url)?url:"?NodeKey=" + nNodeKey;
      document.tv_context_5.href = (url)?url:"?NodeKey=" + nNodeKey;
      document.tv_context_6.href = (url)?url:"?NodeKey=" + nNodeKey;
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = showMenu;
      }
}



I also fixed --showMenu()-- because when you scroll down a page context menu is appears to be loosing it's X,Y coordination... and also some code which you will see down below...

function showMenu (evt) {
  if (MenuIsOn=="Y")
  {      MenuIsOn="N"
      if (document.getElementById) {
            document.getElementById('contextMenu').style.pixelLeft = event.clientX+document.body.scrollLeft;   //  for IE
            document.getElementById('contextMenu').style.pixelTop = event.clientY+document.body.scrollTop;
            document.getElementById('contextMenu').style.visibility = 'visible';
            return false;
      }
      else if (document.layers) {
            if (evt.which == 3) {
            document.contextMenu.left = evt.x+window.pageXOffset;         // for NN
            document.contextMenu.top = evt.y+window.pageYOffset;
            document.contextMenu.onmouseout =
            function (evt) { this.visibility = 'hide'; };
            document.contextMenu.visibility = 'show';
            return false;
            }
      }
      return true;
      }
}

cheers!
 dave
0
 
jahlifeAuthor Commented:
Dave,

Works great, and Thanks for your time and support also on the ShowMenu function as I was unaware here.

Excellent,
Jahlife

>> For review, below is how I am setting up the object to call ContextMenu:

TreeView.NavDHTML = "oncontextmenu=ContextMenu('" & escape( Request.QueryString("process_desc") ) & "','" & escape( Request.QueryString("lookup_type_desc") ) & "','#TVK#','#TVI#')"

Node.DHTML = "oncontextmenu=ContextMenu('" & escape( Request.QueryString("process_desc") ) & "','" & escape( Request.QueryString("lookup_type_desc") ) & "','#TVK#','#TVI#')"

>> And below is how I am translating a ContextMenu function based on your input.  I can alter the url.asp reference as needed and add final variables, great:

function ContextMenu(process_desc,lookup_type_desc,sNode,Node) {
      MenuIsOn = "Y";

      if (document.all)      
      document.all.tv_context_1.href = "url.asp?process_desc=" + process_desc  + "&lookup_type_desc=" + lookup_type_desc + "&sNode=" + sNode + "&Node=" + Node;
      document.all.tv_context_2.href = "url.asp?process_desc=" + process_desc  + "&lookup_type_desc=" + lookup_type_desc + "&sNode=" + sNode + "&Node=" + Node;
      document.all.tv_context_3.href = "url.asp?process_desc=" + process_desc  + "&lookup_type_desc=" + lookup_type_desc + "&sNode=" + sNode + "&Node=" + Node;
      document.all.tv_context_4.href = "url.asp?process_desc=" + process_desc  + "&lookup_type_desc=" + lookup_type_desc + "&sNode=" + sNode + "&Node=" + Node;
      document.all.tv_context_5.href = "url.asp?process_desc=" + process_desc  + "&lookup_type_desc=" + lookup_type_desc + "&sNode=" + sNode + "&Node=" + Node;
      document.all.tv_context_6.href = "url.asp?process_desc=" + process_desc  + "&lookup_type_desc=" + lookup_type_desc + "&sNode=" + sNode + "&Node=" + Node;
      document.oncontextmenu =showMenu;
      if (document.layers) {
      document.tv_context_1.href = "url.asp?process_desc=" + process_desc  + "&lookup_type_desc=" + lookup_type_desc + "&sNode=" + sNode + "&Node=" + Node;
      document.tv_context_2.href = "url.asp?process_desc=" + process_desc  + "&lookup_type_desc=" + lookup_type_desc + "&sNode=" + sNode + "&Node=" + Node;
      document.tv_context_3.href = "url.asp?process_desc=" + process_desc  + "&lookup_type_desc=" + lookup_type_desc + "&sNode=" + sNode + "&Node=" + Node;
      document.tv_context_4.href = "url.asp?process_desc=" + process_desc  + "&lookup_type_desc=" + lookup_type_desc + "&sNode=" + sNode + "&Node=" + Node;
      document.tv_context_5.href = "url.asp?process_desc=" + process_desc  + "&lookup_type_desc=" + lookup_type_desc + "&sNode=" + sNode + "&Node=" + Node;
      document.tv_context_6.href = "url.asp?process_desc=" + process_desc  + "&lookup_type_desc=" + lookup_type_desc + "&sNode=" + sNode + "&Node=" + Node;
      document.captureEvents(Event.MOUSEDOWN);
      document.onmousedown = showMenu;
      }
}


0
 
davidlars99Commented:
well, what can I say, I'm glad to be helpful. Good luck

dave
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now