?
Solved

Using Javascript - Aspx.vb

Posted on 2004-08-26
5
Medium Priority
?
529 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
[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
  • 3
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
AerosSaga earned 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month13 days, 23 hours left to enroll

801 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