Solved

How can I fire my (existing) custom control on hyperlink click?

Posted on 2008-10-20
3
297 Views
Last Modified: 2013-11-18
I have developed a custom control (stored locally) that when called from a web page reads a local XML file, interprets the data and returns formatted HTML to be included on the calling web page.  I can hard code a filename in the control call and it all works.  Now I need to include a variable list of more than one filename (as hyperlinks) on the web page.  The user should be able to click a link and the control will be called (again) passing the selected filename and updating the page with the returned HTML.  FYI the returned HTML fills out the middle of a <table> with rows/cols including inline styles, color, fonts, etc.

I'm not sure where to start.  I'm not sure how to repaint the updated HTML without a page refresh.  And since all the processing is done locally (client side - no server), I think  a page refresh would lose the user's selection anyway.  I guess I could use Javascript (or even vbs) to update the DOM with values, but my control returns pretty complicated HTML.  I'd end up writing more js code to interpret the returned HTML and mapping that to the DOM than is reasonable.  If this is the only way I'd probably be better off rewriting my control to return the XML and process it on the page in Javascript to update the DOM.  But honestly I'm not really feel qualified to take that on. I'm hoping there is something I'm missing...

Here is an example that calls my control.
<html>
<body>
<!-- THIS CODE WILL WORK CALLING THE FILE C:\StaticFile1.xml -->
  <table width="100%">	
    <tr>
      <td>Table Heading</td>
    </tr>
    <!-- THE REST OF THE TABLE IS CREATED BY OUR ACTIVE X CONTROL... -->
  
      <script language="vbscript">
        set obj = CreateObject("MyHelper.MyHelper")
        str = obj.ProcessMWTSummary( "C:\StaticFile1.xml")
        document.writeln(str)  
        set obj = nothing
      </script>
  
  </table>
</body>
</html>
 
 
Obviously the vbs would be moved to a sub but this gives an idea what I need to do:
<html>
<body>
<!-- I NEED SOMETHING LIKE THIS THAT WILL UPDATE THE TABLE CONTENTS BASED ON THE USER SELECTION -->
 
  <p><a href="C:\file1.xml">File1</a></p>  <!-- click any of these and the filename is passed -->
  <p><a href="C:\file2.xml">File2</a></p>  <!-- to the vbs, the control is called and the HTML is updated -->
  <p><a href="c:\file3.xml">File3</a></p>
 
  <table width="100%">	
    <tr>
      <td>Table Heading</td>
    </tr>
    <!-- THE REST OF THE TABLE IS CREATED BY OUR ACTIVE X CONTROL... -->
  
      <script language="vbscript">
        set obj = CreateObject("MyHelper.MyHelper")
        str = obj.ProcessMWTSummary( "{CHANGES BASED ON USER SELECTION}")
        document.writeln(str)  
        set obj = nothing
      </script>
  
  </table>
</body>
</html>

Open in new window

0
Comment
Question by:graylint
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22800755
try:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
<head>
<title></title>
<style type="text/css">
<!--
.file{text-decoration:underline;color:blue;}
-->
</style>
<script language="vbcript" type="text/vbscript">
Sub executeControl(file,o)
	'change the text color so it appears as a "visited link"
	o.style.color="#990099"
 
	Set obj = CreateObject("MyHelper.MyHelper")
	document.getElementById("result").innerHTML = "<table width='100%'><tr><td>Table Heading</td></tr>" & obj.ProcessMWTSummary(file) & "</table>"
	Set obj = nothing
End Sub
</script>
</head>
<body>
<!-- I NEED SOMETHING LIKE THIS THAT WILL UPDATE THE TABLE CONTENTS BASED ON THE USER SELECTION -->
 
  <p><a class="file" onclick='call executeControl("C:\file1.xml",Me)'>File1</a></p>  <!-- click any of these and the filename is passed -->
  <p><a class="file" onclick='call executeControl("C:\file2.xml",Me)'>File2</a></p>  <!-- to the vbs, the control is called and the HTML is updated -->
  <p><a class="file" onclick='call executeControl("c:\file3.xml",Me)'>File3</a></p>
 
	<div id="result"></div>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:graylint
ID: 31508163
We are busy reworking the control right now so I can't test your suggestion just yet.  But I do understand what you are suggesting and I think it is a good plan.  I didn't want to make you wait for the points on this.  I appreciate your answer.

There will be details to work out, but you gave me a great start.  Hopefully you won't mind if I have a quick question if I run into a jam once I get to test your plan.  I don't expect to since your solution is very clear.

Thanks so much for your help! - Robert
0
 

Author Comment

by:graylint
ID: 22806199
Thanks for your suggestion Hielo!  Your plan looks good and your code is very clear.

Thanks again for your help!
- Robert
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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…

734 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