Solved

VisualASP: Passing QueryString for oncontextmenu Function

Posted on 2004-08-21
9
621 Views
Last Modified: 2011-09-20
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
Comment
Question by:jahlife
  • 5
  • 4
9 Comments
 
LVL 13

Expert Comment

by:davidlars99
Comment Utility
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
 
LVL 1

Author Comment

by:jahlife
Comment Utility
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
 
LVL 13

Expert Comment

by:davidlars99
Comment Utility
when you come back make sure you post all error messages and other  problems
0
 
LVL 1

Author Comment

by:jahlife
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 13

Expert Comment

by:davidlars99
Comment Utility
yeah, that would be perfect. Let me see the entire generated page
0
 
LVL 1

Author Comment

by:jahlife
Comment Utility
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
 
LVL 13

Accepted Solution

by:
davidlars99 earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:jahlife
Comment Utility
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
 
LVL 13

Expert Comment

by:davidlars99
Comment Utility
well, what can I say, I'm glad to be helpful. Good luck

dave
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now