Thursday, February 1, 2007

Getting to the instance of your object when using ObjectDataSource

Sometimes when using ObjectDataSource you need to have access to the object that ObjectDataSource is using. Maybe you have a custom constructor you need to call, maybe you need to hook up an event handler, etc.

Once again, ASP.Net 2.0 comes through.

The ObjectCreated event on ObjectDataSource:

protected void ObjectDataSource1_ObjectCreated(object sender, ObjectDataSourceEventArgs e)

{

BLL bll = (BLL)e.ObjectInstance;

bll.haveToSetThis = "not really";

}

You should also look at ObjectCreating event since can be used to actually create the instance of the object.

No comments: