Summary of the use of related events in ObjectDataSoruce and FormViw when a new record is added

Source: Internet
Author: User

First, when you press the commandName = "Insert" button in FormView,. NET will first execute the OnInserted event of object data source. This event has a parameter of the ObjectDataSourceStatusEventArgs type: it has several attributes that we will use:

1. e. Exception -- indicates the Exception object that occurs when the call is added. If an Exception occurs on the called target object, view the InnerException object to obtain more information.
2. e. ExceptionHandled -- indicates whether to mark the exception as handled. If it is set to true, the exception will not be passed to the subsequent event.
3. e. ReturnValue -- indicates the value returned by the InsertMethod you set on the object data source. You can check whether the value is successful.

Then ,. NET will execute the FormView OnItemInserted event. If the ExceptionHandled of the previous object data source is not set to true, Exception will be passed in to this event. This event has a FormViewInsertedEventArgss type parameter: it has several attributes that we will use:
1. e. ExceptionHandled -- indicates whether to mark the exception as handled. If it is set to true, the exception will not be passed to the Page. Error Event. Otherwise, if Page. error Event, first execute Page. error event, if the Page. error does not execute Server. clearError () method, exception passed in Application_Error event. page not defined. when an Error event is handled, the Application_Error event is directly passed in.
2. e. keepinsertmode -- whether to keep the Insert mode. Normally, if an error occurs, an error message is displayed, which is kept in the Insert mode for users to modify.

 


Protected override void OnError (EventArgs e)
{
// If fvFixingResult_ItemInserted and objdsFixingResult_Inserted
// Didn't set ExceptionHandled = true, this event will be called.
Exception ex = Server. GetLastError ();
If (ex! = Null)
{
LblErrorMessage. Text = ex. Message;
}
Server. ClearError ();
}

Protected void fvFixingResult_ItemInserted (object sender, FormViewInsertedEventArgs e)
{
If (! E. ExceptionHandled & e. Exception! = Null)
{
E. ExceptionHandled = true;
E. KeepInInsertMode = true;
}
Else
{
CloseWindow ();
}
}

Protected void objdsFixingResult_Inserted (object sender, ObjectDataSourceStatusEventArgs e)
{
If (e. Exception! = Null)
{
// E. ExceptionHandled = true;
LogManager. AddActivity ("Add <Fixing Result-ELNZC>", false );
If (e. Exception. InnerException! = Null & e. Exception. InnerException is FixingDateDuplicatedException)
{
FixingDateDuplicatedException fx = e. Exception. InnerException as FixingDateDuplicatedException;
LblErrorMessage. Text = MessageManager. GetMessage (fx. MessageID, Language). MessageDesc;
}
Else
{
LblErrorMessage. Text = MessageManager. GetMessage (SysMessage. COMMON_SAVE_FAILED, Language). MessageDesc;
}
}
Else
{
LogManager. AddActivity ("Add <Fixing Result-ELNZC>, data key:" + e. ReturnValue );
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.