hibbardc
asked on
Open a new window within the aspx.cs page with ASP.NET (C#)
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.ImageClickEv entArgs e)
{
string openPrintPage = "";
openPrintPage = "<script language='javascript'>";
openPrintPage += "window.open('Assess-Repor tView.aspx ?OrgReview ID=" + AssessmentID + "&Section=PrintView');";
openPrintPage += "</script>";
btnPrint.Attributes.Add("o nClick", 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!
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.ImageClickEv
{
string openPrintPage = "";
openPrintPage = "<script language='javascript'>";
openPrintPage += "window.open('Assess-Repor
openPrintPage += "</script>";
btnPrint.Attributes.Add("o
}
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!
ASKER
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.
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.
Well, you really don't have to create a new page. You can just flag the same page and only output that javascript.
ASKER
Better yet! How would I do that?
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-Repor tView.aspx ?OrgReview ID=" + Request.QueryString["id"] + "&Section=PrintView');";
openPrintPage += "</script>";
btnPrint.Attributes.Add("o nClick", openPrintPage);
}
private void btnPrint_Click(object sender, System.Web.UI.ImageClickEv entArgs e)
{
Response.Redirect("default .aspx?prin t=true&id= " + AssessmentID)'
Response.End();
}
It's been a while since I've done C# stuff, so sorry about the syntax
With your pageInit...
if Request.QueryString["print
{
loadPage()
}
private void loadPage()
{
string openPrintPage = "";
openPrintPage = "<script language='javascript'>";
openPrintPage += "window.open('Assess-Repor
openPrintPage += "</script>";
btnPrint.Attributes.Add("o
}
private void btnPrint_Click(object sender, System.Web.UI.ImageClickEv
{
Response.Redirect("default
Response.End();
}
It's been a while since I've done C# stuff, so sorry about the syntax
ASKER
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["prin t"] == "true")
{
loadPage();
}
}
************************** *****
Juuuusstt making sure I have everything in the right place.
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["prin
{
loadPage();
}
}
**************************
Juuuusstt making sure I have everything in the right place.
Yea, whatever function runs whenever the page is loaded first.
ASKER
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.....
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.....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
When I did this for a project, I had to post the javascript before the aspx was rendered.