2009-11-05 37 views
5

hoạt động trên asp.net vs05. Tôi biết làm thế nào để hiển thị popup, trong cú pháp dưới đây của tôi tôi hiển thị một popup khi một trang được load.But tôi muốn hiển thị popup này sau khi một số hành động xảy ra trên máy chủ, tôi có một nút, dưới sự kiện nút này tôi muốn làm một số công việc về phía máy chủ, sau đó tôi muốn hiển thị thông báo popup .Here là cú pháp hoàn chỉnh của tôi có thể hiển thị cửa sổ bật lênCách hiển thị thông báo bật lên từ phía máy chủ

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>Untitled Page</title> 

    <script src="scripts/jquery-1.3.2.min.js" type="text/javascript"></script> 

     <script type = "text/javascript"> 

    $(document).ready(function() { 
    $("#message").fadeIn("slow"); 
    $("#message a.close-notify").click(function() { 
     $("#message").fadeOut("slow"); 
     return false; 
    }); 
}); 
</script> 

    <link href="StyleSheet.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div id='message' style="display: none;"> 
    <span>Hey, This is my Message.</span> 
    <a href="#" class="close-notify">X</a> 
</div> 

    </form> 
</body> 
</html> 

Giống như cú pháp ở trên tôi muốn hiển thị thông báo popup từ phía máy chủ sau khi một số sự kiện xảy ra .Here là aspx của tôi cú pháp:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server"> 
    <title>Untitled Page</title> 

    <script src="scripts/jquery-1.3.2.min.js" type="text/javascript"></script> 

     <script type = "text/javascript"> 
    function computeCorrectValue(type parameter) 
    { 

      $(document).ready(function() { 
      $("#message").fadeIn("slow"); 
      $("#message a.close-notify").click(function() { 
       $("#message").fadeOut("slow"); 
       return false; 
      }); 
     }); 


    }  
</script> 

</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
     <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div> 
    </form> 
</body> 
</html> 

C# cú pháp:

using System; 
using System.Data; 
using System.Configuration; 
using System.Collections; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 

public partial class Default4 : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
    protected void Button1_Click(object sender, EventArgs e) 
    { 
     //want to do some work then want 


     Button1.Attributes.Add("onclick", "javascript:computeCorrectValue(parameter)"); 
    } 
} 

Giúp tôi hiển thị thông báo bật lên sau khi một số sự kiện xảy ra trên máy chủ side.popup phải giống như ví dụ đầu tiên của tôi .i cũng có thể hiển thị thông báo cảnh báo, nhưng tôi không muốn hiển thị thông báo cảnh báo.url http://stackoverflow.com/questions/659199/how-to-show-popup-message-like-in-stackoverflow tôi muốn điều tương tự nhưng muốn hiển thị sau sự kiện máy chủ.

Trả lời

4

Đối với một giải pháp công nghệ thấp mà giữ kịch bản trong mẫu trang của bạn, bạn có thể thêm video này vào HTML của bạn (điều này có thể đi vào $(document).ready() thay):

<script type="text/javascript"> 

var missingInfo = '<%= this.MissingInfo %>' == 'True'; 
if (missingInfo) { 
    alert('Not enough information. Please try again.'); 
} 

</script> 

Và thêm một tài sản được bảo vệ để trang của bạn :

private bool missingInfo = false; 

protected bool MissingInfo { 
    get { return this.missingInfo; } 
} 

protected void Button1_Click(object sender, EventArgs e) { 
    // Button1 stuff ... 
    // ... then if you want to show the alert 
    this.missingInfo = true; 
} 
10
protected void Button1_Click(object sender, EventArgs e) 
    { 
     ScriptManager.RegisterStartupScript(
      this, 
      this.GetType(), 
      "popup", 
      "alert('hello');", 
      true); 
    } 
+0

+1 Giải pháp tốt :) – Somebody

3
string script = string.Format("alert('this is alert');"); 
     ScriptManager.RegisterClientScriptBlock(Page, typeof(System.Web.UI.Page), "redirect", script, true); 
0

Mặc dù mã ví dụ trong câu trả lời khác đang sử dụng cảnh báo, đó chỉ là một ví dụ. Đặt chức năng của bạn ở vị trí cảnh báo và bạn sẽ có cửa sổ bật lên của mình.

Đây là mã Darin với cuộc gọi chức năng của bạn:

protected void Button1_Click(object sender, EventArgs e) { 
    ScriptManager.RegisterStartupScript(
     this, 
     this.GetType(), 
     "popup", 
     "computeCorrectValue(parameter);", 
     true); 
} 

Mặc dù tôi thực sự không chắc chắn nơi bạn đang nhận được các tham số được truyền vào hàm của bạn.

Các vấn đề liên quan