HelloBD
HelloBD

Reputation: 387

How to show popup message from server side

work on asp.net vs05. i know how to show popup ,in my below syntax i show a popup when a page is load.But i want to show this popup after some action occur on server ,i have a button ,under this button event i want to do some work on server side ,then i want to show popup message .Here is my complete syntax that can show popup

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

Like the above syntax i want to show popup message from server side after some event occur .Here is my aspx syntax:

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

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

Help me to show popup message after some event occur on server side.popup must look like my give first example .i can show alert message too ,but i don't want to show alert message.url http://stackoverflow.com/questions/659199/how-to-show-popup-message-like-in-stackoverflow i want same thing but want to show after server event.

Upvotes: 5

Views: 25109

Answers (4)

Jeff Sternal
Jeff Sternal

Reputation: 48583

For a low-tech solution that keeps the script in your page template, you could add this to your HTML (this could go in $(document).ready() instead):

<script type="text/javascript">

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

</script>

And add a protected property to your Page:

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

Upvotes: 4

Jason Berkan
Jason Berkan

Reputation: 8884

While the example code in the other answers are using alert, that is just an example. Put your function in place of alert and you will have your popup.

Here is Darin's code with your function call:

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

Though I'm really not sure where you are getting the parameter that is passed into your function.

Upvotes: 0

Pragnesh Patel
Pragnesh Patel

Reputation: 1444

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

Upvotes: 3

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

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

Upvotes: 11

Related Questions