Solved

Using Javascript - Aspx.vb

Posted on 2004-08-26
5
528 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 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

Technology Partners: 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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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