2012-09-10 181 views
1

只是問一個直接的問題,當我完成在我的頁面中添加一些數據,然後單擊提交按鈕時,如何使一個彈出窗口說明信息已成功添加到數據庫中而不是創建一個新的頁?我有什麼辦法可以做?任何網站被引用?由於提交後彈出窗口

+0

您是否從答案中得到任何幫助? – freebird

+0

還沒有。我試圖通過1 1的建議回答:) –

回答

0

你可以爲它創建一個可重複使用的功能。

public void Show(string msg) 
    { 
      Page page = HttpContext.Current.Handler as Page; 
      if (page != null) 
      { 
       ScriptManager.RegisterStartupScript(page, page.GetType(), "msg", "alert('" + msg + "');", true); 
      } 
    } 

並提交像這樣的按鈕調用。

protected void btnSubmit_Click(object sender, EventArgs e) 
{ 
     // Your Code for submit 
     Show("Save Success"); 
} 
+0

對於可重用函數的建議。 – freebird

1

你只是把下面的代碼:

Response.Write("<script>alert('information has been successfully added') 
       </script>"); 
+1

我認爲使用Response.Write方法不是一個好的做法。 – freebird

0

你可以設置你的消息的標籤文本並使其可見,當你要顯示的消息。

lblMessage.Text = "Data updated successfully"; 
lblMessage.Visible = true; 

爲了使它突出,你可以使用jQuery dialogs,並與CSS樣式它恰如其分。

0
//Global Declaration 
public static void Message(String message, Control cntrl) 
{ 
    ScriptManager.RegisterStartupScript(cntrl, cntrl.GetType(), "alert", "alert('" + message + "');", true); 
} 


//Call any where, where you want to display message 
Message("Any message here", this); 
+0

你可以編輯你的答案。有點令我困惑。謝謝:) –

0
ScriptManager.RegisterStartupScript(this, this.GetType(), "Notification", "alert('Done');", true); 
0

使用ASP.NET你將仍處於一個完整的頁面生命週期,如果你是一個經常提交行爲提交表單。這意味着該頁面首先需要重新加載,然後才能觸發警報。如果你不想重新加載頁面,而只是顯示一個結果警報,你需要用AJAX執行你的操作,將表單發佈到一個服務方法,該方法更新你擁有的數據庫。這不會重新加載你的頁面,只會顯示你的ajax調用完成的提醒。 jQuery $.post()

0

在您點擊按鈕檢查有效數據後,您可以使用ClientScriptManager.RegisterStartupScript Method

這裏是你彈出

做這樣的事情

ClientScriptManager script = Page.ClientScript 

if (!script.IsStartupScriptRegistered(GetType(), "Show Popup")) 
{ 
    script.RegisterStartupScript(GetType(), "Show Popup", "ShowPopup();", true); 
} 

您可以從code behind調用javascript功能

HTML:

<div id="Popup"></div> 

CSS:

#Popup 
{ 

    height:200px; 
    width:300px; 
    position:fixed; 
    z-index:102; 
    left:50%; 
    top:50%; 
    margin-top:-130px; 
    margin-left:-180px; 
    font-weight:bold; 
    font-size:10pt; 
    padding:20px; 
    background-color:#fff; 
    border:10px solid #9cc3f7; 
    border-radius:20px; 
    -webkit-border-radius:20px; 
    -moz-border-radius:20px; 
    text-align:center; 
    display:none; 
}​ 

jQuery函數:

function ShowPopup() 
{ 

$('#Popup').show("slow"); 

}​ 

See Sample