保存按钮不显示消息并在单击时重定向 [英] Save Button not displaying message and redirecting when clicked

查看:85
本文介绍了保存按钮不显示消息并在单击时重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页表单,上面有文本框和验证器。当用户单击保存按钮时,应显示一条消息,然后将用户重定向回其主页。消息和重定向不起作用。我做错了什么?



保存按钮属性:

I have a web form that has textboxes and validators on it. When the user clicks on the Save button there should be a message to display and then redirects user back to their home page. The message and the redirect doesn't work. What did I do wrong?

Save Button Properties:

<asp:Button ID="ButtonSave" runat="server" onclick="ButtonSave_Click" 

                    style="font-weight: 700" Text="Save" Width="100px" 

                    CausesValidation="False" />





Code Behind :



Code Behind:

protected void ButtonSave_Click(object sender, EventArgs e)
    {
        SqlConnection con7 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
        con7.Open();

        SqlCommand cmd = new SqlCommand("Insert into Table345 (INST_ID, FT_UNDERGR, DATE, FT_GRAD, FTE_UNDERG, FTE_GRAD, NON_CREDIT, TOTAL_FTE, FCFTUHC, FCFTPBHC, FCPTUHC, FCPTPBHC, NCHC, UnderG12, Postb9, Total123b4b, FTEYR, THCAS) values (@INST_ID, @FT_UNDERGR, @DATE, @FT_GRAD, @FTE_UNDERG, @FTE_GRAD, @NON_CREDIT, @TOTAL_FTE, @FCFTUHC, @FCFTPBHC, @FCPTUHC, @FCPTPBHC, @NCHC, @UnderG12, @Postb9, @Total123b4b, @FTEYR, @THCAS);", con7);

        cmd.CommandType = CommandType.Text;

        cmd.Parameters.AddWithValue("@INST_ID", TextBoxINST_ID.Text);
        cmd.Parameters.AddWithValue("@FT_UNDERGR", TextBoxFTUG.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@FT_GRAD", TextBoxFTG.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@FTE_UNDERG", TextBoxTHUGDR.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@FTE_GRAD", TextBoxTHGDR.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@NON_CREDIT", TextBoxNCCDR.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@TOTAL_FTE", TextBoxTCNC.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@FCFTUHC", TextBoxTNFUG.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@FCFTPBHC", TextBoxTNFG.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@FCPTUHC", TextBoxTNCPUG.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@FCPTPBHC", TextBoxTNCPG.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@NCHC", TextBoxTNNCC.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@FTEYR", lblYEAR1.Text);
        cmd.Parameters.AddWithValue("@DATE", TextBoxDATE.Text);
        cmd.Parameters.AddWithValue("@UnderG12", TextBoxTHUG.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@Postb9", TextBoxTHG.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@Total123b4b", TextBoxT1234.Text.Replace(",", ""));
        cmd.Parameters.AddWithValue("@THCAS", TextBoxTHCAS.Text.Replace(",", ""));

        cmd.ExecuteNonQuery();

        if (true)
        {
            SqlConnection con88 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
            con88.Open();
            SqlCommand level = new SqlCommand("select accessLevel, INST_ID from Tablepass where INST_ID = @INST_ID AND accessLevel = @accessLevel", con88);
            level.Parameters.Add(new SqlParameter("INST_ID", TextBoxINST_ID.Text));
            level.Parameters.Add(new SqlParameter("accessLevel", TextBoxaccessLevel.Text));

            SqlDataReader reader = level.ExecuteReader();
            DataTable dt1 = new DataTable();
            dt1.Load(reader);

            foreach (DataRow dr1 in dt1.Rows)
            {
                int returnedLevel = Convert.ToInt32(dr1[0].ToString());
                int accessLevel = Convert.ToInt32(dr1[1].ToString());
                Session["accessLevel"] = accessLevel;

                if (returnedLevel == 1)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='FormAPublic.aspx';", true);
                }
                else if (returnedLevel == 11)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='FormAPublicL.aspx';", true);
                }
                else if (returnedLevel == 7)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='CEOPage.aspx';", true);
                }
                else if (returnedLevel == 3)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='FormDPrivateFor.aspx';", true);
                }
                else if (returnedLevel == 31)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='FormDPrivateForL.aspx';", true);
                }
                else if (returnedLevel == 2)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='FormCPrivateNon.aspx';", true);
                }
                else if (returnedLevel == 21)
                {
                    ScriptManager.RegisterStartupScript(this, typeof(Page), "myscript", "alert('You Have Successfully Saved the Enrollment Profile. You may come back to finish entering your data later. You will now be redirect to the Menu Page');location.href='FormCPrivateNonL.aspx';", true);
                }
                con88.Close();
            }
        }
    }
}

推荐答案

我现在正在使用它。我的代码中有一点小事。我有这个:



I have it working now. One little small thing in my code. I had this:

if (true)
        {
            SqlConnection con88 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
            con88.Open();





我将其更改为:



I changed it to this:

if (Page.IsValid)
        {
            SqlConnection con88 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
            con88.Open();


这篇关于保存按钮不显示消息并在单击时重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆