Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 534
  • Last Modified:

Printing A Gridview and Keeping the Gridview Visible

Hello-  I'm simply trying to print a GridView that is in my ASP.NET Page.  I am using the function below which works well in this environment.  After I click print or cancel the grid on the page disappears.  My question is how can I print and once the print window closes be right back on the same page with the grid and the buttons?  Do I have to reload the grid?  I am new to the .net environment.  Thanks.

function CallPrint( strid )
{
var prtContent = document.getElementById( strid );
// var strOldOne=prtContent.innerHTML;
var WinPrint = window.open('', '', 'left=0,top=0,width=1000,height=1000,status=0');
WinPrint.document.write( prtContent.innerHTML );
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.print();
WinPrint.close();
// prtContent.innerHTML=strOldOne;
}

0
thamilto0410
Asked:
thamilto0410
  • 3
  • 2
1 Solution
 
it_saigeDeveloperCommented:
Most likely you are using a button control that has [runat=server] embedded in the markup.  If this is true, then you are doing a postback to the server.  The gridview disappearing is the result of that post back.

Either you will need to reload the grid or use a client-side version of your script without issuing a postback.

-saige-
0
 
thamilto0410Author Commented:
it_saige:  So if I use an html button and add the javascript function to it this will resolve my problem?
0
 
it_saigeDeveloperCommented:
You could remove runat=server from the asp.net element.  So long as you do not need to do a postback this is perfectly valid.

-saige-
0
 
thamilto0410Author Commented:
New to all this so learning.  I did as you said and it worked perfect.  Thanks.
0
 
thamilto0410Author Commented:
Thanks for the assistance.  Sometimes it can be something simple but if your new to the technology you need a push in the right direction.  That is exactly what I got.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now