Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In my project there is a print button . after clicking that button I want to open a popup but it's not loading
ASP.NET
<table class="inputForm">
<tfoot>
	<tr>
		<td align="right">
		    <asp:Button ID="btnPrint" OnClick="btnPrint_Click" Text="Printuiuiuiui" CssClass="button" runat="server" Visible="true" />
		</td>
	</tr>
</tfoot>
</table>

In .cs file

C#
Page.ClientScript.RegisterStartupScript(typeof(Page), "s1", "openViewer('" + (int)ABCDEF.enReportName.PortfolioPrint + "');");

openViewer is a function that shows popup
JavaScript
function openViewer(reportName) {

  sPath = "/ADDCD/Popups/ifggfjfj.aspx?Viewer.aspx?ReportName=" + reportName;
   
  if (navigator.userAgent.indexOf("Chrome") != -1) {

    return window.open(sPath, self, "dialogHeight: 374px; dialogWidth: 430px; status: no; resizable: no; center: yes;");
  }
  else if (navigator.userAgent.indexOf("Firefox") != -1) {

    return window.open(sPath, self, "dialogHeight: 374px; dialogWidth: 430px; status: no; resizable: no; center: yes;");
  }
  else if ((navigator.userAgent.indexOf("MSIE") != -1) || (!!document.documentMode == true)) { //IF IE > 10
           
    return window.showModalDialog(sPath, self, "dialogHeight: 374px; dialogWidth: 430px; status: no; resizable: no; center: yes;");

  }
}

I tried with Page.ClientScript.RegisterStartupScriptBlock but not working . Anybody have any idea why it's not working?

What I have tried:

I tried with this
C#
Page.ClientScript.RegisterStartupScript(typeof(Page), "openViewer", 
    "openViewer(" + (int)ABCDEF.enReportName.PortfolioPrint + ");", true);
Posted
Updated 24-May-21 4:43am
v4

1 solution

Pretty much every browser these days has an integrated popup blocker. This will prevent Javascript from opening new windows unless it's in response to a user action like clicking on a button.

Your code is trying to open a popup window as soon as the page loads. That will be blocked by the popup blocker. And no, there is no way around that, short of asking your users to disable their popup blockers. Any workaround would be a security vulnerability in the browser, which would be patched PDQ.

Instead, you need to avoid a postback to the server, and open your popup window as soon as the user clicks on the button. How easy that is to do will depend on what else you're doing when the user clicks the button.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900