2009-11-05 14 views
5

funziona su asp.net vs05. so come mostrare i popup, nella mia sintassi sottostante mostro un popup quando una pagina viene caricata. Ma voglio mostrare questo popup dopo che si è verificata qualche azione sul server, ho un pulsante, sotto questo evento pulsante voglio fare un po 'di lavoro sul lato server, quindi voglio mostrare messaggio popup .Qui è la mia sintassi completa che può mostrare pop-upCome mostrare il messaggio popup dal lato server

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

Come la sintassi di cui sopra voglio mostrare un messaggio pop-up dal lato server dopo qualche evento verificarsi .Qui è il mio aspx sintassi:

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

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

Aiutami a mostrare un messaggio popup dopo che si sono verificati alcuni eventi sul server side.popup deve apparire come il mio primo esempio .i può mostrare anche un messaggio di avviso, ma non voglio mostrare messaggio di avviso.url http://stackoverflow.com/questions/659199/how-to-show-popup-message-like-in-stackoverflow voglio la stessa cosa ma voglio mostrare dopo l'evento del server.

risposta

4

Per una soluzione low-tech che mantiene lo script nel vostro modello di pagina, è possibile aggiungere questo per il codice HTML (questo potrebbe andare in $(document).ready() invece):

<script type="text/javascript"> 

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

</script> 

E aggiungere una proprietà protetta alla tua Pagina :

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 Soluzione piacevole :) – Somebody

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

Mentre il codice di esempio in altre risposte utilizzano avviso, questo è solo un esempio. Metti la tua funzione al posto di avviso e avrai il tuo popup.

Ecco il codice di Darin con la chiamata di funzione:

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

Anche se io non sono davvero sicuro dove hai trovato il parametro che viene passato nella vostra funzione.

Problemi correlati