2009-11-05 15 views
5

asp.net vs05 पर काम करें। मुझे पता है कि पॉपअप कैसे दिखाना है, मेरे नीचे दिए गए वाक्यविन्यास में, जब कोई पृष्ठ लोड होता है तो मैं पॉपअप दिखाता हूं। लेकिन सर्वर पर कुछ क्रिया होने के बाद मैं यह पॉपअप दिखाना चाहता हूं, मेरे पास एक बटन है, इस बटन ईवेंट के तहत मैं कुछ काम करना चाहता हूं सर्वर साइड पर, तो मैं दिखाने के लिए पॉपअप संदेश .Here मेरा पूरा वाक्य रचना है कि पॉपअपसर्वर पक्ष से पॉपअप संदेश कैसे दिखाएं

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

दिखा सकते हैं इसके बाद के संस्करण वाक्य रचना मैं किसी घटना के बाद सर्वर साइड से पॉपअप संदेश दिखाना चाहते हैं की तरह होते हैं .Here मेरी 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> 

सी # वाक्यविन्यास:

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 मुझे एक ही चीज़ चाहिए लेकिन सर्वर घटना के बाद दिखाना चाहते हैं।

उत्तर

4

एक कम तकनीकी समाधान है कि अपने पृष्ठ टेम्पलेट में स्क्रिप्ट रहता है के लिए, आप अपने 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; 
} 
10
protected void Button1_Click(object sender, EventArgs e) 
    { 
     ScriptManager.RegisterStartupScript(
      this, 
      this.GetType(), 
      "popup", 
      "alert('hello');", 
      true); 
    } 
+0

+1 अच्छा समाधान :) – Somebody

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

अन्य उत्तर में उदाहरण कोड चेतावनी का उपयोग कर रहे हैं, कि सिर्फ एक उदाहरण है। अपने कार्य को अलर्ट के स्थान पर रखें और आपके पास पॉपअप होगा।

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

हालांकि मैं वास्तव में यकीन है कि जहां पैरामीटर है कि आपके समारोह में पारित हो जाता हो रही है नहीं कर रहा हूँ:

यहाँ अपने समारोह कॉल के साथ डैरिन के कोड है।

संबंधित मुद्दे