Click here to Skip to main content
15,919,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me i do not want to show successfully message in again insertation in page.

C#
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;
    }
}
Posted
Updated 6-Feb-12 5:19am
v2
Comments
[no name] 6-Feb-12 23:46pm    
just set Label2.Text = string empty.
then it will not show u the message.........

Hi,

Try to hide the label in Page_Load...
 
Share this answer
 
Add a hidden variable to the page, and by default set it to "N".
ASP.NET
<asp:hiddenfield id="DisplayedAlready" runat="server" value="N" xmlns:asp="#unknown" />

and inside
C#
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
     }
}


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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900