Solved

Open a new window within the aspx.cs page with ASP.NET (C#)

Posted on 2003-11-19
11
1,334 Views
Last Modified: 2010-05-18
I hope you can help --

I've been having a difficult time with this one.  I need to be able to open a new window (to show a 'printer-friendly' version of the page) and I keep running into problems.

And the code on the aspx.cs page:

private void btnPrint_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string openPrintPage = "";                        
openPrintPage = "<script language='javascript'>";
   
openPrintPage += "window.open('Assess-ReportView.aspx?OrgReviewID=" + AssessmentID + "&Section=PrintView');";

openPrintPage += "</script>";

btnPrint.Attributes.Add("onClick", openPrintPage);
}

When ran, it doesn't open to a new page.  It appears to do an autopostback and "erase" the data on-screen without ever opening a new window.

Thanks in advance!
0
Comment
Question by:hibbardc
  • 5
  • 4
11 Comments
 
LVL 11

Expert Comment

by:thunderchicken
ID: 9779316
This might be a quick fix, but you could create that on a new page, then redirect it to that page.

When I did this for a project, I had to post the javascript before the aspx was rendered.
0
 

Author Comment

by:hibbardc
ID: 9779530
Hi thunderchicken,

Hmmm, good suggestions, but with the app in testing, I know we're trying not to have to create new pages or redirect to newly created pages.



0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 9779543
Well, you really don't have to create a new page.  You can just flag the same page and only output that javascript.
0
 

Author Comment

by:hibbardc
ID: 9779565
Better yet!  How would I do that?
0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 9779589
Something along the lines of this  (say your aspx page is called default.aspx)

With your pageInit...


if Request.QueryString["print"] == "true"
{
   loadPage()
}



private void loadPage()
{
string openPrintPage = "";                        
openPrintPage = "<script language='javascript'>";
   
openPrintPage += "window.open('Assess-ReportView.aspx?OrgReviewID=" + Request.QueryString["id"] + "&Section=PrintView');";

openPrintPage += "</script>";

btnPrint.Attributes.Add("onClick", openPrintPage);
}

private void btnPrint_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
   Response.Redirect("default.aspx?print=true&id=" + AssessmentID)'
   Response.End();
}



It's been a while since I've done C# stuff, so sorry about the syntax
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:hibbardc
ID: 9779741
Quick question:

For placing code within the pageInt, is this what you meant?

******************************************

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
    //
    // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    //
      InitializeComponent();
      base.OnInit(e);

      //to print page -- sample code
      if (Request.QueryString["print"] == "true")
      {
      loadPage();
      }
}
*******************************

Juuuusstt making sure I have everything in the right place.
0
 
LVL 11

Expert Comment

by:thunderchicken
ID: 9779752
Yea, whatever function runs whenever the page is loaded first.
0
 

Author Comment

by:hibbardc
ID: 9780867
Hello again.

When I incorporated the code, some headers began to show up (their disabled depending on user level), so I may have to mess with this one some more.....
0
 
LVL 11

Accepted Solution

by:
thunderchicken earned 500 total points
ID: 9780881
You could do a

Response.Write("Please wait...");
Response.Redirect("default.aspx?print=true&id=" + AssessmentID)'
   Response.End();
0
 
LVL 6

Expert Comment

by:masirof
ID: 12784157
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:
Accept: thunderchicken

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

masirof
EE Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now