Solved

Using Javascript - Aspx.vb

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 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