0

I am trying to do some error handling in item inserting for my formview. If anyone forgets to enter a value in tutorial section, the error message will detect it is null and give a popup of it being null. however, my visual studio does not recognize Exception or ExceptionHandled. The error is that there is no definition for Exception. I have searched high and low and I don't know what the problem is. Any ideas will be appreciated.

protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
{

    if (e.Exception != Null)
    {
        string msg = "";
        if (e.Exception.Message.Containts("NULL"))
        {
            msg = "Tutorial Section cannot be empty.";
        }
        else
            msg = "unknown";
        ClientScript.RegisterStartupScript(this.GetType(), "myalert", "window.setTimeout(\"alert('" + msg + "')\",0);", true);
        e.ExceptionHandled = true;
    }
}
4
  • 1
    what you are saying I guess means validation rather error handling. Commented Jan 12, 2015 at 10:49
  • that's not it. I just want to know how come the e.Exception is not recognized. Commented Jan 12, 2015 at 10:55
  • @NegarNegaru it simply doesn't exists. FormViewInsertEventArgs Class Commented Jan 12, 2015 at 10:56
  • I see. I assumed since it exists in listview it should exist in formview as well. Thanks. Commented Jan 12, 2015 at 11:50

1 Answer 1

1

protected void FormView1_ItemInserting event has no Exception

You have to use Inserted event handler, not Inserting event!

Like this:

protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
{
    if (e.Exception != null)
    {
        Label1.Text = "Error : " + e.Exception.Message;

        e.ExceptionHandled = true;
    }
     else
     {
        Label1.Text = "Inserted Successfully";
     }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.