Solved

Using Javascript - Aspx.vb

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used.

792 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