Can anyone tell me how or what's the code for the following:
1. I have two frames on my web page. (Top and Bottom)
2. Top Frame is data
3. Bottom Frame are some Controls. (Print button, Back Button, Close Button.)
4. I do not want to use Java.
5. I'm using VB.Net creating aspx pages.

Question: I would like to do an Audit of who Prints out my Page of the Top Frame. I have the audit code figured out but I would like to know if there's a way to Press the print button and Print the Page. If the page was successful printed I would update my sql database and create an audit that It was printed. I have been looking for this type of code for one week already. Please Help... Thanks

You mean, you don't want to use "JavaScript". Java and JavaScript are not related to each other and have nothing in common.

You cannot know if a user actually printed. Printing is firmly in the hands of the user - a web developer cannot write code to force a user to print.

You can, however, create a "Print" button, and USING JAVASCRIPT, invoke the "window.print()" method when they press it. Again, USING JAVASCRIPT, you can author a hidden form variable, then submit the form. Your code-behind page would read the hidden form variable to know that the user clicked your "Print" button.

I know you said you didn't want "to use Java (sic)", but there is no way to do it otherwise. Web development involves both server-side and client-side scripting. If you ignore client-side scripting, you're only doing half the job!

If you need help with the JavaScript portions, post a question in the JavaScript/DHTML forum.

Well as you can tell I'm VERY new to this... Okay So I need to learn Java... Would you happen to know how the code might look like regarding your last statement? "You can author a hidden form variable, then submit the form. Your code-behind page would read the hidden form variable to know that the user clicked your "Print" button."

Or is there a way to print without using Java? Just by clicking the Button and using the web control button to excute the Printing. Is this possible? Do I have to use Java? I'm a VB6 Programmer and I have been able to do this in VB6. I thought that when you create a WebControl Button it will come back to the server when you press the button. Is this not true? Help... I'm going crazy..

Any ASP.NET code executes on the server. So yes, you can print something, but it will print to your web server's default printer, if there is one. I assume you want to let the user print something from their browser. You need client-side code to that.

Once more, it's "JavaScript" - Java is a completely different animal. If you ask questions about "Java", you'll get answers about "Java", which won't be relevant.

I'd be happy to help you more, but we're off-topic. You should post a new question in the JavaScript/DHTML forum.

Regarding ASP.NET Web Server Controls. They GENERATE html code.

So, an ASP.NET Web Server Button Control, creates an <input type="button"> element.

What is different about the Web Server Button Control, is that it has server-side events, properties, and methods.

So in Visual Studio.NET, you drag a button control over onto your form. Double-click it, and a code window appears. Any code you enter there will run ON THE SERVER.

What happens is, the user browses to the page, and IIS/ASP.NET renders a page for the user. The user sees a button, and clicks it. That particular click is a client-side event, and unless you code some JavaScript, nothing in particular happens. The form does submit, however, and that's where ASP.NET does a lot of house-keeping to remember that is has a "BUTTON", and that the BUTTON was clicked, and it must run the code you authored.

But none of that helps you with your problem, because printing is a client-side affair.

Really, in your scenario, you don't NEED a WebServer Button Control. A normal html button element, will work just fine:

<input type="button" onclick="window.print();" />

That is the basis of your solution.

This article has been dead for over six months. Start a new discussion instead.