在response.end之后调用alert

时间:2017-07-17 11:00:22

标签: javascript c# asp.net

这是我的代码,我试图在响应后显示警报。但没有显示os警报

string filepath =  ConfigurationManager.AppSettings["USPPath"].ToString() + urlPDF;
                FileInfo file = new FileInfo(Server.MapPath(filepath));

if (file.Exists)
{
ClientScript.RegisterStartupScript(this.GetType(), "somekey", "alert('Some data missing!');", true);   
Response.ClearContent();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);

Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/pdf";
Response.TransmitFile(file.FullName);
try
{
    Response.Flush();
    ClientScript.RegisterStartupScript(this.GetType(), "somekeyqw","alert('Some data missing!'); ", true);
   // DisplaySucessAlert(true, "Shipping Label downloaded successfully.");
   // ScriptManager.RegisterStartupScript(this, this.GetType(), "Popalertxs", "normalalert();", true);
}
 finally
 {
  // DisplaySucessAlert(true, "Shipping Label downloaded successfully.");
  //  ScriptManager.RegisterStartupScript(this, this.GetType(), "Popalert", "normalalert();", true);
 }
}

我使用过更新面板,html代码看起来像

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
 <ContentTemplate>
<asp:Button ID="btnuspsgenerate" class="btn-def" runat="server" Text="Download USPS label" OnClick="btnuspsgenerate_Click" />  

</ContentTemplate>
<Triggers>
    <asp:PostBackTrigger ControlID="btnuspsgenerate" />
</Triggers>
</asp:UpdatePanel>

我的pdf文件下载但未显示警告。 在这里,我曾经使用过很多方法,但却无法表现出警觉性。

我评论过的一些代码,因为它们不起作用

1 个答案:

答案 0 :(得分:0)

当您使用更新面板时,您无法像这样调用javascript ..

尝试以下代码,

string CloseWindow;       
CloseWindow = "alert('Hello World')"; 
ScriptManager.RegisterStartupScript(UpdatePanelID,UpdatePanelID.GetType(), "CloseWindow", CloseWindow, true);