Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RegisterStartupScript not working inside an Update Panel to open file in new tab in asp.net

Tags:

asp.net

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>");
like image 923
user2486976 Avatar asked Jul 12 '13 08:07

user2486976


1 Answers

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.

like image 54
Gayatri Avatar answered Nov 04 '22 12:11

Gayatri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!