ASP.NET with C#

I am trying insert values into data base.using ASP.Net(C#).

Emp Name: Textbox (validation ontrol Required field)

Emp Id :  TextBox

Country : Text box

Submit Button

* After successfull insertion i want to display it in label like "Successfully Inserted".
Up to here No issues. I am able to do.

Now again i removed text box value.click it on submit.Validation is coming fine.But "Successfully Inserted message  " still there.

I want to clear of this message when i click second time sumbit button if any validation happens.
mannevenu26Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Monica PSoftware DeveloperCommented:
Hi

In button click event check for the page is valid or not and then make the insert statement to get executed

   
  
        if (Page.IsValid)
        {
               -- Write the database insertion code here            
                   Literal1.Text = "Inserted successfully";
        }
       

Open in new window

0
XGISCommented:
Hello mannevenu26,  There are a number of things you can try,

The C# event is fine to use, but you may also consider a message box that the user confirms with an OK button and the message disappears.  This can be easier than implementing behind code logic that fires based on events.
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "test", "<script>alert('Successfully Inserted.....!');</script>");

Open in new window

In some cases this may report as deprecated but should still work, otherwise if you want to keep using C# consider using postback logic in the button click event to make the label invisible.  eg
if (Page.IsPostBack) Label1.Visible = false;

Open in new window

here are some other postback samples for button click events which included C# case logic;  Just replace telerik:radbutton with asp:button
Postback button message samples
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vishal KedarCommented:
Write below code in button click event.

button1_Click()
{
    Label1.Text = "";
   //OR
       Label1.Text = string.Empty;

     //Remaining code


}
0
ShaileshEECommented:
Write below code in button click event.

button1_Click()
{
 
   {
       //code for Insert
   }
 
       Label1.Text = string.Empty; 

     //Remaining code


}

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.