2012-09-10 68 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