RegisterStartupScript未在更新面板中工作,无法在asp.net的“新建”选项卡中打开文件

RegisterStartupScript未在更新面板中工作,无法在asp.net的“新建”选项卡中打开文件,asp.net,Asp.net,我试图在更新面板中使用ScriptManager.RegisterStartupScript在gridview中的链接按钮的单击事件时在“新建”选项卡中打开一个文件,但它不起作用。代码如下: filename = Server.UrlEncode(filename); string js = "<script>window.open('ViewReports.aspx?filename=" + Server.UrlEncode(file

我试图在更新面板中使用ScriptManager.RegisterStartupScript在gridview中的链接按钮的单击事件时在“新建”选项卡中打开一个文件,但它不起作用。代码如下:

       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);
当我在更新面板外使用以下代码时,它可以工作:

         Type cstype = this.GetType();

        ClientScriptManager cs = Page.ClientScript;
        cs.RegisterStartupScript(cstype, "dateSrpt", "<script>window.open('ViewReports.aspx?filename=" + Server.UrlEncode(filename) + "', '_newtab');</script>");
Type cstype=this.GetType();
ClientScriptManager cs=Page.ClientScript;
cs.RegisterStartupScript(cstype,“dateSrpt”,“window.open('ViewReports.aspx?filename=“+Server.UrlEncode(filename)+”,'u newtab'););

您的内联javascript有问题。它不适用于内联javascript。当我将它作为单独的javascript函数分离到aspx页面并在Registerstartupscript中调用该函数时,它工作了

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代码

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

请这样尝试,它可以工作。

您添加了registerStartupscript()代码块的哪个事件?请尝试将其添加到page_Prerender事件中。实际上,我正在尝试在linkbutton的click事件中打开一个文件。所以这个代码被放置在链接按钮的点击事件中。受保护的无效lnkvwReport_单击(对象发送方,事件参数e)尝试
RegisterClientScriptBlock
而不是
RegisterStartupScript
的副本。不存在接受5个参数的
ScriptManager.RegisterStartupScript
重载。为什么/如何传递updatepanel1?
ScriptManager.RegisterStartupScript(updatepanel1, updatepanel1.GetType(), "Pop up", "OpenPopup();", true);