Solved

Using Javascript - Aspx.vb

Posted on 2004-08-26
5
521 Views
Last Modified: 2012-08-14
I'm very new to .Net and I'm working on a webapp that uses an aspx.vb file for all the code.  I want to use a button's onClick event to display some components on a webform.  I'm using <div> tags to control the showing and hiding.  I've found a couple of websites that set the div display property by calling a javascript function.  I place this javascript code in the html portion of the aspx file.  When it runs, it says it can't find the function in the aspx.vb file.  Am I putting the code in the wrong place or is there is a way to put javascript in the aspx.vb file?  Thanks...
0
Comment
Question by:Bryan2662
  • 3
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
AerosSaga earned 125 total points
ID: 11904277
You would need to do it like this, this prints divs using java:

<div id="printReady">
<p>Hello World! Your Printable Page Content Goes Here</p>
</div>

<script language="JavaScript">
var gAutoPrint = true; // Flag for whether or not to automatically call the print function

function printSpecial()
{
      if (document.getElementById != null)
      {
            var html = '<HTML>\n<HEAD>\n';

            if (document.getElementsByTagName != null)
            {
                  var headTags = document.getElementsByTagName("head");
                  if (headTags.length > 0)
                        html += headTags[0].innerHTML;
            }
            
            html += '\n</HE>\n<BODY>\n';
            
            var printReadyElem = document.getElementById("printReady");
            
            if (printReadyElem != null)
            {
                        html += printReadyElem.innerHTML;
            }
            else
            {
                  alert("Could not find the printReady section in the HTML");
                  return;
            }
                  
            html += '\n</BO>\n</HT>';
            
            var printWin = window.open("","printSpecial");
            printWin.document.open();
            printWin.document.write(html);
            printWin.document.close();
            if (gAutoPrint)
                  printWin.print();
      }
      else
      {
            alert("Sorry, the print ready feature is only available in modern browsers.");
      }
}

</script>

Test Link:
<a href="javascript:void(printSpecial())">Print this Page</a>  

Test Button
<form id="printMe" name="printMe">
  <input type="button" name="printMe" onClick="printSpecial()" value="Print this Page">
</form>  
 
Regards,

Aeros
0
 

Author Comment

by:Bryan2662
ID: 11904440
Yes, I do something very similar to this and here is the error I get:

BC30456: 'toggle' is not a member of 'ASP.WebForm2_aspx'.

where toggle is the name of the javascript function that I created in the html portion of the aspx page.  
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11904867
well then its not registering your script, or theres a syntax error.  Are your Form tags well formed?  Is your html well formed are you using user controls that have extra html etc?  If its not firing the script then thats the issue.
0
 

Author Comment

by:Bryan2662
ID: 11905464
Ok, I think I may have figured it out.  The javascript is fine.  Apparently you cannot use the onclick event of a Webform button but you can use the onclick event of an html button.  

I guess if I wanted to use the webform button I would have to figure out a way to achieve the same thing in the aspx.vb page...
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11905483
glad to see you got it straightened out.

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

9 Experts available now in Live!

Get 1:1 Help Now