ObjectDataSource in a web part?
Hello All,
My code below works perfectly when I put it in an ASP.NET application (default.aspx code behind for example), but as soon as I put it in a web part (compile it into an assembly and place it into GAC) I get this error:
"The type specified in the TypeName property of ObjectDataSource"
ObjectDataSource objDataSrc =newObjectDataSource("Fully qualified name of my type","select method name");
objDataSrc.SelectParameters.Add("Perosnid","123");
GridView grdViewPersons =newGridView();
grdViewPersons.AutoGenerateColumns =false;
grdViewPersons.DataSource = objDataSrc;
grdViewPersons.DataBind();
this.form1.Controls.Add(grdViewPersons);
First of all, both assemblies (web part and my BLL assembly which objectdatasource calls into) are installed into CAG.
Secondly, If I don’t use objectdatasoure and directly call into the BLL, web part works fine , it just does not work with objectDatasource. I know that objectdatasourcer uses reflection to find the select method in the assembly (my BLL), so there should be a problem around the reflection when both assemblies are placed into the GAC
Any help would be appreciated.
Thanks
[3298 byte] By [
RayCan] at [2008-3-3]
Hi,
Can you specify on which line of code the error returns? The last line will probably not work:
this.form1.Controls.Add(grdViewPersons);
Can you change it to:
this.Controls.Add(grdViewPersons);
Thing is, 'this' is the webpart, which is already a control on the Page. The webpart probably does not have a 'from1'.
I hope this helps
- Mart
Sorry , in the web part I had already changed the this.form1.Controls.Add(grdViewPersons); to this.Controls.Add(grdViewPersons);. That's not a problem.
I guess probelm is the reflection that datasourceobject uses in order to bind itself to my BLL and its select method. It seems when both web part and BLL are installed in the CAG this reflection does not work. I have strongly named all the assemblies and added them to the safecontrol tag of my web.config.
The thing is, when I do NOT use the objectdatasource by directly calling into my BLL , web part works fine , but when I try to bind the GridView or FormView to the objectdatasource I get these errors . It says the type "my assembly" can not be found.Strange!!!!!
Thanks for your reply though
I have a similar problem. I have a objectdatasource that has a DataObjectTypeName that points to a object thats within a GAC assembly. When i run the code to update the objectdatasource. I get the following error below. If i place this GAC assembly in my web bin directory, the code works. Any help is appreciated. Thanks in advance
System.InvalidOperationException: The data object type specified in the DataObjectTypeName property of ObjectDataSource 'ObjectDataSource_LinkDetails' could not be found.
at System.Web.UI.WebControls.ObjectDataSourceView.TryGetDataObjectType()
at System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues)
at System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCall
Actually i have a little workaround which won't help me though.
You can add a reference to the gac assembly in the webconfig file. But since i'm using a in-house framework i don't have the ability to modify the webconfig file to add my assembly. Does anyone know a way to reference my dll.
I currently have a objectdatasource that just updates a object. my page also adds and deletes these object but i don't use the objectdatasource to do this and it works fine which is of course at compile time. So i know my web app can has a reference to the dll in the gac. BUT for some reason the ObjectDataSource doesn't since its during run-time i'm assuming. Sounds like the objectdatasource is a little inefficient. Maybe i'm attacking the problem wrong. Let me know what you think..thanks
I found a work around that might help you but not me. You can modify the web.config file to add a reference to the dll in the gac. I can't do this since i'm using a web.config thats from a in-house framework and i'm not allowed to update it.
I have a objectdatasource that its only job is to select and update a object is compiled in a dll in the gac. My page also add and deletes this object but it doesn't use the objectdatasource and it works fine. Does anyone know a way to make this work. I know 2 workarounds that i've found. One is the one i mentioned in the beginning of the message, the other is to have a copy of the gac dll in your web/ bin directory. Sounds inefficient though. Does anyone know what i'm talking about. Seems like the objectdatasource is inefficient when dealing w/ run-time objects.