在数据库中添加数据后,我想添加Javascript,因此从Javascript警报我应该得到消息是否提交数据 [英] After Adding Data In Database I Want To Add Javascript, So That From Javascript Alert I Should Get Message Whether Data Is Submitted Or Not
本文介绍了在数据库中添加数据后,我想添加Javascript,因此从Javascript警报我应该得到消息是否提交数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在按钮点击的数据库中添加一些数据。在数据库中添加数据后,我想添加javascript,从javascript提醒我应该收到数据是否已提交的消息。
I want to add some data in database on button click.After adding data in Database i want to add javascript, from javascript alert i should get message whether data is submitted or not.
protected void btn1_Click(object sender, EventArgs e)
{
using (con = new SqlConnection(strcon))
{
cmd = new SqlCommand("insert into Emp_details (name,emp_code,dept_name,designation,mngr_name,DOJ,band)values (@name,@emp_code,@dept_name,@designation,@mngr_name,@DOJ,@band)", con);
//cmd.CommandText = "insert into Emp_details (name,emp_code,dept_name,designation,mngr_name,DOJ,band)values (@ame,@emp_code,@dept_name,@designation,@mngr_name,@DOJ,@band)";
con.Open();
cmd.Parameters.AddWithValue("@name",TextBox1.Text);
cmd.Parameters.AddWithValue("@emp_code",TextBox2.Text);
cmd.Parameters.AddWithValue("@dept_name",TextBox3.Text);
cmd.Parameters.AddWithValue("@designation",TextBox4.Text);
cmd.Parameters.AddWithValue("@mngr_name",TextBox5.Text);
cmd.Parameters.AddWithValue("@DOJ",TextBox6.Text);
cmd.Parameters.AddWithValue("@band", TextBox7.Text);
int i = cmd.ExecuteNonQuery();
if (i == 1)
{
Label1.Text ="Submitted";
}
else
{
Label1.Text = "Not Submitted";
}
}
而不是这个
Instead of this
if (i == 1)
{
Label1.Text ="Submitted";
}
else
{
Label1.Text = "Not Submitted";
}
i想要添加javascript是否提交数据。
然而我用过 -
i want add javascript whether data is submitted or not.
However i used-
<asp:Button ID="btn1" runat="server" Text="Submit" onclick="btn1_Click" OnClientClick="javascript:alert('Submitted');"/>
请给出适当的编码..
kindly give appropriate coding..
推荐答案
Page.ClientScript.RegisterStartupScript(this, GetType(), "ALERT", "alert('Submitted')", true);
或
Or
Page.ClientScript.RegisterClientScriptBlock(this, GetType(), "ALERT", "alert('Submitted')", true);
或者你可以创建扩展方法来显示如下警告
Or you can create extention method to show alerts like below
using System;
using System.Web.UI;
//put your namespace here..
namespace yourNamespace
{
public static class Extensions
{
public static void ShowAlert(this Control control, string message)
{
if (!control.Page.ClientScript.IsClientScriptBlockRegistered("PopupScript"))
{
control.Page.ClientScript.RegisterClientScriptBlock(control.Page.GetType(), "PopupScript", String.Format("alert('{0}')", message), true);
//if you using ajax toolkit and need to show alerts with update panel
//ScriptManager.RegisterClientScriptBlock(control.Page, control.Page.GetType(), "PopupScript", String.Format("alert('{0}')", message), false);
}
}
}
}
之后调用它如下
after that call it as below
if (i == 1)
{
this.ShowAlert("Submitted");
}
else
{
this.ShowAlert("Not Submitted");
}
这篇关于在数据库中添加数据后,我想添加Javascript,因此从Javascript警报我应该得到消息是否提交数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文