1

In my project there is a print button . after clicking that button I want to open a popup but it's not loading

   <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>
Page.ClientScript.RegisterStartupScript(typeof(Page), "s1", "<script FOR=window EVENT=onload>openViewer('" + (int)ABCDEF.enReportName.PortfolioPrint + "');</script>");

openViewer is a function that shows popup


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?

5
  • Have your tried with Page.ClientScript.RegisterClientScriptBlock instead of Page.ClientScript.RegisterStartupScript? learn.microsoft.com/en-us/dotnet/api/…
    – M. Ruiz
    May 28, 2021 at 1:43
  • if you don't use the <asp:button with server-side code, simply you can use the input type button, and then put our code. but if you are using server-side before showing the popup page, then you can pass a parameter to query string to indicate the javascript to open a popup once the response return from the server May 30, 2021 at 3:41
  • @M.Ruiz I tried ut not working at all
    – muniya
    May 31, 2021 at 20:00
  • @AhmadHindash I don't want to change asp utton to input type
    – muniya
    May 31, 2021 at 20:01
  • I tried it and your code and it worked as expected. Make sure your openViewer function is defined before the call, e.g. try to move the openViewer function to a script in the head of the page.
    – M. Ruiz
    Jun 1, 2021 at 22:45

1 Answer 1

1

It's been a while but try this. Move all the script tags and JS to the page. I think just call the function with the arguments it needs.

Page.ClientScript.RegisterStartupScript(typeof(Page), "openViewer", 
    "openViewer(" + (int)ABCDEF.enReportName.PortfolioPrint + ");", true);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.