public partial class Person_ForeignKeyField : ForeignKeyField
{}
I naively assumed this would behave the same as the foreign key field if I used it in the UI:
[UIHint("Person")]
public Object Person;
but I get an immediate unhandled exception:
Object reference not set to an instance of an object.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 33: protected string GetDisplayString()
Line 34: {
Line 35: object value = FieldValue; Line 36: Line 37: if (value == null)
Source File: C:\Users\pwmfs33\Documents\Visual Studio 2010\Projects\ChildCareQuality\ChildCareQuality\DynamicData\FieldTemplates\ForeignKey.ascx.cs Line:
35
Am I barking up the wrong bush? Is this even possible/advisable?
using System;
using System.Collections.Specialized;
using System.ComponentModel.DataAnnotations;
using System.Web.DynamicData;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ChildCareQuality
{
public partial class Person_ForeignKeyField : ForeignKeyField
{
}
}
I'm trying to derive from the 'standard' ForeignKey.ascx and ForeignKey.ascx.cs files from the installed ASP.NET Dynamic Data Entities Web Application
Ultimately, it's more important to me to derive controls from the ForeignKey_EditField control and class, but it seemed simpler to start with ForeignKeyField. If I can't even get that to work, there's no point moving forward.
Ideally, my next step would be to derive a Person_ForeignKey_Field control from the ForeignKey_Field control, adding controls for Last & First name to look them up in the database. From there, I want to derive a Teacher_ForeignKey_Field from Person, adding
license #. I don't want to copy/paste the Last, First controls from Person for reuse in Teacher. Later, I expect to derive classes from teacher, and so on.
I don't see why this should be even considered as something which someone has to pay for, specially when there is not support at all from Microsoft in the matter of disclosing how to write proper code for Dynamic Data apps. How much will be charged for solving
this? C'mon, don't make me laugh ...
You can go to Csharpbits NotAClue blog and you'll find a 1,000 working examples ... for free !!!!
And don't take me wrong and please don't you dare to patronize me for saying this. It has been demonstrated a 1,00 times here so there will be no need to defend something which is undefendable ... moreover, that's what I think and have said many times here
before
REGARDING THE QUESTION .... if you see the ASP.Net official videos dating from 2008 you'll find the answer. You don't need to "derive" from a FK control in order to create a new one BUT you must make a copy of it (renamig accordingly the page and its code)
and there you go .... !!!!!
Your question falls into the paid support category which requires a more in-depth level of support. Please visit the below link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone
Below is the initial analysis of the issue
As a normal behaviour it works. Also I noticed that you are deriving the Control from ForeignKey Field. we should be deriving it from FieldTemplateUserControl. Please follow it using following links
I don't understand "As a normal behaviour it works." What does that mean?
I get the same error if I derive from FieldTemplateUserControl. Besides, since ForeignKey is derived from FieldTemplateUserControl, I wouldn't expect that to avoid the error.
pwmfs33
Member
14 Points
13 Posts
Deriving from DynamicData ForeignKey FieldTemplate
Jan 25, 2013 12:50 PM|LINK
Hi all,
I'm getting started on building my own DynamicData field templates, using the existing ForeignKey as the base class. So far, I'm stumped at step 1.
I've tried to register the exisiting ForeignKey control within what I call the Person control:
and simply derive Person_ForeignKeyField from
public partial class Person_ForeignKeyField : ForeignKeyField {}I naively assumed this would behave the same as the foreign key field if I used it in the UI:
[UIHint("Person")] public Object Person;but I get an immediate unhandled exception:
Object reference not set to an instance of an object.
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 33: protected string GetDisplayString() Line 34: { Line 35: object value = FieldValue; Line 36: Line 37: if (value == null)Source File: C:\Users\pwmfs33\Documents\Visual Studio 2010\Projects\ChildCareQuality\ChildCareQuality\DynamicData\FieldTemplates\ForeignKey.ascx.cs Line: 35
Am I barking up the wrong bush? Is this even possible/advisable?
Thanks in advance for any advice.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Deriving from DynamicData ForeignKey FieldTemplate
Jan 27, 2013 12:54 AM|LINK
Hi,
Have you used this in the Dynamic Data Template?
Can you show us your aspx codes?
pwmfs33
Member
14 Points
13 Posts
Re: Deriving from DynamicData ForeignKey FieldTemplate
Jan 29, 2013 01:51 PM|LINK
Yes, I am trying this in a DynamicData FieltTemplate, by which I mean this is my /DynamicData/FieldTemplates/Person.ascx file:
and this is my Person.ascx.cs CodeBehind:
using System; using System.Collections.Specialized; using System.ComponentModel.DataAnnotations; using System.Web.DynamicData; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace ChildCareQuality { public partial class Person_ForeignKeyField : ForeignKeyField { } }I'm trying to derive from the 'standard' ForeignKey.ascx and ForeignKey.ascx.cs files from the installed ASP.NET Dynamic Data Entities Web Application
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Deriving from DynamicData ForeignKey FieldTemplate
Jan 30, 2013 12:09 AM|LINK
Hi,
I'm not sure why you wanna inherit from the ForeignKeyField class? What actually do you wanna do?
pwmfs33
Member
14 Points
13 Posts
Re: Deriving from DynamicData ForeignKey FieldTemplate
Jan 30, 2013 02:42 PM|LINK
Ultimately, it's more important to me to derive controls from the ForeignKey_EditField control and class, but it seemed simpler to start with ForeignKeyField. If I can't even get that to work, there's no point moving forward.
Ideally, my next step would be to derive a Person_ForeignKey_Field control from the ForeignKey_Field control, adding controls for Last & First name to look them up in the database. From there, I want to derive a Teacher_ForeignKey_Field from Person, adding license #. I don't want to copy/paste the Last, First controls from Person for reuse in Teacher. Later, I expect to derive classes from teacher, and so on.
klca
Member
507 Points
413 Posts
Re: Deriving from DynamicData ForeignKey FieldTemplate
Feb 08, 2013 01:15 AM|LINK
Hi,
I don't see why this should be even considered as something which someone has to pay for, specially when there is not support at all from Microsoft in the matter of disclosing how to write proper code for Dynamic Data apps. How much will be charged for solving this? C'mon, don't make me laugh ...
You can go to Csharpbits NotAClue blog and you'll find a 1,000 working examples ... for free !!!!
And don't take me wrong and please don't you dare to patronize me for saying this. It has been demonstrated a 1,00 times here so there will be no need to defend something which is undefendable ... moreover, that's what I think and have said many times here before
REGARDING THE QUESTION .... if you see the ASP.Net official videos dating from 2008 you'll find the answer. You don't need to "derive" from a FK control in order to create a new one BUT you must make a copy of it (renamig accordingly the page and its code) and there you go .... !!!!!
Carlos N. Porras
(El Salvador)
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Deriving from DynamicData ForeignKey FieldTemplate
Feb 08, 2013 08:12 AM|LINK
Hi,
I've submitted your issue to our Microsoft's inner senior group to analyze, maybe it will take some time to analyze your issue.
Please be patient.
Reguards!
Parashuram
Member
98 Points
39 Posts
Re: Deriving from DynamicData ForeignKey FieldTemplate
Feb 14, 2013 01:39 AM|LINK
Your question falls into the paid support category which requires a more in-depth level of support. Please visit the below link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone
Below is the initial analysis of the issue
As a normal behaviour it works. Also I noticed that you are deriving the Control from ForeignKey Field. we should be deriving it from FieldTemplateUserControl. Please follow it using following links
http://msdn.microsoft.com/en-us/magazine/gg535665.aspx http://msdn.microsoft.com/en-us/library/cc488522(v=vs.100).aspx http://blogs.msdn.com/b/kaevans/archive/2009/03/12/asp-net-dynamic-data-and-displaying-images-with-a-custom-field-template.aspx
pwmfs33
Member
14 Points
13 Posts
Re: Deriving from DynamicData ForeignKey FieldTemplate
Feb 14, 2013 04:17 PM|LINK
I don't understand "As a normal behaviour it works." What does that mean?
I get the same error if I derive from FieldTemplateUserControl. Besides, since ForeignKey is derived from FieldTemplateUserControl, I wouldn't expect that to avoid the error.
klca
Member
507 Points
413 Posts
Re: Deriving from DynamicData ForeignKey FieldTemplate
Feb 15, 2013 04:06 AM|LINK
Hi,
You SHOULD see the videos I told you. Answer is there. Custom filters are based on copies of field templates and not derived from them .....
Carlos N. Porras
(El SaLvador)