单击提交按钮时未显示消息框 [英] Message Box not showing when submit button is clicked
本文介绍了单击提交按钮时未显示消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个消息框代码,用于显示用户点击提交按钮但未显示的情况。我做错了什么?代码是对的吗?
I have a code for a messagebox to show when the user clicks on the submit button but it does not show. What did I do wrong? Is the code right?
protected void Submit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HOTConnectionString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Insert into Table2013 (INST_ID, UNITID, ASTUDENTS, ACOMPLETED, ATRANSFERS, BSTUDENTS, BCOMPLETED, BTRANSFERS, YEAR, DATE) values (@INST_ID, @UNITID, @ASTUDENTS, @ACOMPLETED, @ATRANSFERS, @BSTUDENTS, @BCOMPLETED, @BTRANSFERS, @YEAR, @DATE)Insert into Table2014 (INST_ID, UNITID, ASTUDENTS, ACOMPLETED, ATRANSFERS, BSTUDENTS, BCOMPLETED, BTRANSFERS, YEAR, DATE) values (@INST_ID, @UNITID, @ASTUDENTS, @ACOMPLETED, @ATRANSFERS, @BSTUDENTS, @BCOMPLETED, @BTRANSFERS, @YEAR, @DATE)", con);
cmd.Parameters.AddWithValue("@ASTUDENTS", TextBoxTNUGSC.Text);
cmd.Parameters.AddWithValue("@ACOMPLETED", TextBoxTNUGSCD.Text);
cmd.Parameters.AddWithValue("@ATRANSFERS", TextBoxTTOUG.Text);
cmd.Parameters.AddWithValue("@BSTUDENTS", TextBoxTNGSC.Text);
cmd.Parameters.AddWithValue("@BCOMPLETED", TextBoxTNGSCD.Text);
cmd.Parameters.AddWithValue("@BTRANSFERS", TextBoxTTOG.Text);
cmd.Parameters.AddWithValue("@YEAR", TextBoxYEAR.Text);
cmd.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);
cmd.Parameters.AddWithValue("@UNITID", TextBoxUNITID.Text);
cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
try
{
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("Gradrate.aspx");
}
catch (Exception er)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('You Have Successfully Submitted Your Cohort')", true);
}
finally
{
}
}
推荐答案
您需要使用RegisterStartupScript。您刚刚注册了该块,但没有任何内容正在调用该代码。如果您将其注册为启动,则意味着它将在页面加载时运行。但是,我更喜欢标签的想法。我不是个人从C#调用JS的粉丝。
You need to use RegisterStartupScript. You just registered the block but nothing is calling that code. If you register it as a startup that means it will run when the page loads. However, I like the idea of a label much better. I am not a fan of calling JS from C#, personally.
这篇关于单击提交按钮时未显示消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文