在将值提交到数据库后,我使用以下代码在标签中显示成功消息。但它不显示。我是这个领域的新手。请帮我这样做..
protected void btn_submit_Click(object sender, EventArgs e)
{
try
{
//Insert Code is here
ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "<script language='javascript'>UpdateStatus('Record Added Successfully,'Green');</script>", false);
}
catch
{
}
}
UpdateStatus(Message) {
var statusMsg = document.getElementById('lbl_status');
statusMsg.innerHTML = Message;
return false;
}
答案 0 :(得分:0)
这对我来说就像一个与javascript无关的完整回发,你需要做的就是更改标签的文本。我不知道你要对RegisterStartupScript
电话做什么,但这不是它应该如何运作的。只需将标签的文字设置如下......
protected void btn_submit_Click(object sender, EventArgs e)
{
try
{
//Insert Code is here
lbl_status.Text = "Record Added Successfully";
lbl_status.ForeColor = System.Drawing.Color.Green;
}
catch
{
lbl_status.Text = "Error";
lbl_status.ForeColor = System.Drawing.Color.Red;
}
}
只需确保您的标签是runat=server
属性设置
答案 1 :(得分:-1)
这样做
ASP.NET
<asp:Label runat="server" ID="lblMessage"></asp:Label>
在codebehind中
protected void btn_submit_Click(object sender, EventArgs e)
{
try
{
//Insert Code is here
lblMessage.text ="Message Here";
lblMessage.ForeColor = System.Drawing.Color.Green;
}
catch
{
lblMessage.text ="Message Here";
lblMessage.ForeColor = System.Drawing.Color.Red;
}
}
但是如果你想要一个消息框就像这样
protected void btn_submit_Click(object sender, EventArgs e)
{
try
{
//Insert Code is here
ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "Message Here", false);
}
catch
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "temp", "Message Here", false);
}
}
然后将显示消息框。