簡體   English   中英

如何從服務器端顯示彈出消息

[英]How to show popup message from server side

在asp.net vs05上工作。 我知道如何顯示彈出窗口,在我的下面的語法中我顯示一個頁面加載時彈出窗口。但我想在服務器上發生一些操作后顯示此彈出窗口,我有一個按鈕,在此按鈕事件下我想做一些工作在服務器端,然后我想顯示彈出消息。這是我的完整語法,可以顯示彈出窗口

<%@ 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>

像上面的語法一樣,我希望在某些事件發生后顯示來自服務器端的彈出消息。這是我的aspx語法:

<%@ 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#語法:

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)");
    }
}

幫助我在服務器端發生某些事件后顯示彈出消息.popup必須看起來像我的第一個示例。我也可以顯示警告消息,但我不想顯示警告消息.url http://stackoverflow.com/questions/659199/how-to-show-popup-message-like-in-stackoverflow我想要同樣的事情,但想要在服務器事件后顯示。

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

對於將腳本保留在頁面模板中的低技術解決方案,您可以將其添加到HTML中(這可以放在$(document).ready() ):

<script type="text/javascript">

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

</script>

並為您的頁面添加受保護的屬性:

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;
}
string script = string.Format("alert('this is alert');");
        ScriptManager.RegisterClientScriptBlock(Page, typeof(System.Web.UI.Page), "redirect", script, true);

雖然其他答案中的示例代碼使用警報,但這只是一個示例。 將您的功能放在警告的位置,您就會有彈出窗口。

這是Darin的函數調用代碼:

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

雖然我真的不確定你在哪里獲得傳遞給你的函數的參數。

暫無
暫無

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

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