我不想再次显示成功的消息标签提交按钮单击 [英] i do not want to show successfully message label in again Submit button click

查看:63
本文介绍了我不想再次显示成功的消息标签提交按钮单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助我,我不想在页面中再次插入时成功显示消息.

Please help me i do not want to show successfully message in again insertation in page.

protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            string constr;
            constr = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(constr);
 
            con.Open();
            string str = "insert   into  Doe_detail values('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "')";
            SqlCommand cmd = new SqlCommand(str, con);
            cmd.ExecuteNonQuery();
            con.Close();
            Label2.Visible = true;
            Label2.Text = "Data has Been Successfully inserted";
            TextBox1.Text = "";
            TextBox2.Text = "";
            TextBox3.Text = "";
            TextBox4.Text = "";
            TextBox5.Text = "";
        }
        catch (Exception es)
        {
        }
    }
 
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        Label2.Visible = false;
    }
}

推荐答案



尝试在Page_Load中隐藏标签...
Hi,

Try to hide the label in Page_Load...


向页面添加一个隐藏变量,默认情况下将其设置为"N".
Add a hidden variable to the page, and by default set it to "N".
<asp:hiddenfield id="DisplayedAlready" runat="server" value="N" xmlns:asp="#unknown" />


和内部


and inside

protected void Button1_Click(object sender, EventArgs e)
{
     try
     {
       .......
        con.Close();
        if (DisplayedAlready.Value == "N") // not shown till now
        {
            DisplayedAlready.Value == "Y";
            Label2.Visible = true;
            Label2.Text = "Data has Been Successfully inserted";
        }
        else
        {
            Label2.Text = string.Empty; // or whatever you want to do second time
        }
        ......
     }
     catch (Exception es)
     {
          DisplayedAlready.Value = "N";
          // Label2.Text = "Error"; // ????? whatever you want to display
     }
}



另外,如果有任何重置情况,请记住将DisplayedAlready值重置为"N".
看看这是否适合您.



Also remember to reset the value of DisplayedAlready value to "N" if there is any reset case.
See if this works for you.


这篇关于我不想再次显示成功的消息标签提交按钮单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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