簡體   English   中英

響應結束后撥打電話提醒

[英]Call alert after response.end

這是我嘗試在響應后顯示警報的代碼。 但沒有操作系統警報顯示

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文件已下載但未顯示警告。 在這里,我使用了很多方法,但無法顯示警報。

我評論了一些代碼,因為它們不起作用

當您使用更新面板時,則無法像這樣調用JavaScript。

嘗試以下代碼,

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM