2013-08-22 4 views
0

컨트롤에 액세스하려고하면 NULL입니다.ObjectDataSource - DeleteMethod/InsertMethod/UpdateMethod의 Null 페이지 컨트롤

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" ... DeleteMethod="DeleteEntry"> 
public void DeleteEntry(long entryID) 
{ 

    try 
    { 
    ... Delete ... 
    } 
    catch (Exception ex) 
    { 
    lblErrorMessage.Text = ... => lblErrorMessage is NULL! 
    } 
} 

페이지 컨트롤에 액세스 할 수 없습니다. 오류 메시지를 사용자에게 반환하는 다른 방법은 무엇입니까?

답변

1

양식 코드 뒤에 오류를 잡을 수 있습니다. Exception 객체의 하위 클래스를 만들어 던져서 내가 뭘 잡는 지 알 수 있습니다.

페이지 코드 :

protected void ObjectDataSource1_Deleted(object sender, ObjectDataSourceStatusEventArgs e) 
{ 
    if (e.Exception != null) 
    { 
     if (e.Exception.InnerException is MyException) 
     { 
      lblErrorMessage.Text = e.Exception.InnerException.Message; 
      e.ExceptionHandled = true; 
     } 
    } 
} 

개체 코드 :

try 
{ 
    // Whatever 
} 
catch (Exception ex) 
{ 
    throw new MyException(); 
}