5

I am trying to open a file in new tab on click event of a link button inside gridview using ScriptManager.RegisterStartupScript inside update panel, but its not working. The Code is as below :

       filename = Server.UrlEncode(filename);          
       string js = "<script>window.open('ViewReports.aspx?filename=" + Server.UrlEncode(filename) + "', '_newtab');</script>";           
       ScriptManager.RegisterStartupScript(UpdatePanel1,UpdatePanel1.GetType(),"Pop up",js,true);

This also not working:

        ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), js, true);

And when I am using below code outside Update Panel it works:

         Type cstype = this.GetType();

        ClientScriptManager cs = Page.ClientScript;
        cs.RegisterStartupScript(cstype, "dateSrpt", "<script>window.open('ViewReports.aspx?filename=" + Server.UrlEncode(filename) + "', '_newtab');</script>");
user2486976
  • 97
  • 1
  • 1
  • 7
  • Which event have you added the registerStartupscript() code block? Please try adding it to the page_Prerender event. – Gayatri Jul 12 '13 at 08:57
  • Actually I am trying to open a file on click event of linkbutton. So this code is placed in click event of the link button. protected void lnkvwReport_Click(object sender, EventArgs e) – user2486976 Jul 12 '13 at 09:16
  • Try `RegisterClientScriptBlock` instead of `RegisterStartupScript` – Pawan Nogariya Jul 12 '13 at 09:29
  • Duplicate of [RegisterStartupScript doesn't work with ScriptManager,Updatepanel. Why is that?](https://stackoverflow.com/questions/11643578/registerstartupscript-doesnt-work-with-scriptmanager-updatepanel-why-is-that) – TylerH Aug 31 '20 at 20:24

1 Answers1

9

There is problem with your inline javascript. It doesn't work with the inline javascript. when I segregated it to the aspx page as separate javascript function and called the function inside the Registerstartupscript, It worked.

Javascript

function OpenPopup() {            
        window.open('PulseUserManagement.aspx', null, 'height=500, width=1100, status=no,      resizable=no, scrollbars=yes, toolbar=no,location=no, menubar=no');
    }

CS code

ScriptManager.RegisterStartupScript(updatepanel1, updatepanel1.GetType(), "Pop up", "OpenPopup();", true);

Please try like this, it works.

Gayatri
  • 554
  • 3
  • 7
  • 2
    There is no overload of `ScriptManager.RegisterStartupScript` that accepts 5 arguments. Why/how are you passing in updatepanel1? – stevejboyer Dec 19 '14 at 01:04