I think I figured out my problem. When I originally created the Text_RO.ascx user control, I only created "half". I needed to create both the text_RO.ascx AND Text_RO_Edit.ascx. I then had to make the Text_RO_Edit.ascx a literal just like the Text_RO.ascx.
The two user controls work together it appears.
Is this a correct assumption?
Hopefully you will see this post and be able to confirm this question for me and then mark this post as resolved? This was from last Friday.
Hi defyant_2004, I tried the ReadOnly attribute and it works perfect. I think you should place the ReadOnly attribute on top of the property in the auto generated data class, not in your own custom class. This is the easiest way to get things done, but the
only downside is we are modifying the auto gen class...
Sorry too quickly to jump to conclusion. Actually the ReadOnly atttribute doesn't seem to work correctly, at least I can't get it to work correctly. It does shows the column with just text string and without textbox in edit and insert, but if you try to
hit update it won't work, I guess when user hit the update link it tries to write to the ReadOnly field as well, despite user never change the value for that field (Because it's ReadOnly!). It still doen't work even after comment out the setter for that field
in the auto gen class.
Does anyone know how to get this to work? I am using 3.5 SP1, Linq to SQL
I know this is an old post but just want to update it with another solution in case it helps others. In place of the [ReadOnly(true)]
attribute, you can use the [Editable(false)]
attribute on the field you want to display but not allow edits on. If you annotate an Entity Reference (i.e. foreign key relationship) with the
ReadOnly
or Editable
attribute, the editable dropdown list on the Edit page gets replaced with a hyperlink.
defyant_2004
Member
55 Points
337 Posts
Re: Show Field But Do Not Allow Editing
Jan 26, 2009 06:28 PM|LINK
Ricka6,
I think I figured out my problem. When I originally created the Text_RO.ascx user control, I only created "half". I needed to create both the text_RO.ascx AND Text_RO_Edit.ascx. I then had to make the Text_RO_Edit.ascx a literal just like the Text_RO.ascx. The two user controls work together it appears.
Is this a correct assumption?
Hopefully you will see this post and be able to confirm this question for me and then mark this post as resolved? This was from last Friday.
Thanks for help.
ricka6
All-Star
15088 Points
2277 Posts
Microsoft
Moderator
Re: Show Field But Do Not Allow Editing
Jan 26, 2009 06:44 PM|LINK
Yes, that's why I originally suggested One approach would be to copy DynamicData\FieldTemplates\Text.ascx to TextRO_Edit
As when you copy the control, the code behind file is automatically copied too.
defyant_2004
Member
55 Points
337 Posts
Re: Show Field But Do Not Allow Editing
Jan 26, 2009 07:11 PM|LINK
Yes, it was the fact that I did not include _edit.
Thanks again for your help.
zhili
Member
23 Points
15 Posts
Re: Show Field But Do Not Allow Editing
Jan 15, 2010 11:59 PM|LINK
Hi defyant_2004, I tried the ReadOnly attribute and it works perfect. I think you should place the ReadOnly attribute on top of the property in the auto generated data class, not in your own custom class. This is the easiest way to get things done, but the only downside is we are modifying the auto gen class...
zhili
Member
23 Points
15 Posts
Re: Show Field But Do Not Allow Editing
Jan 16, 2010 02:27 AM|LINK
Sorry too quickly to jump to conclusion. Actually the ReadOnly atttribute doesn't seem to work correctly, at least I can't get it to work correctly. It does shows the column with just text string and without textbox in edit and insert, but if you try to hit update it won't work, I guess when user hit the update link it tries to write to the ReadOnly field as well, despite user never change the value for that field (Because it's ReadOnly!). It still doen't work even after comment out the setter for that field in the auto gen class.
Does anyone know how to get this to work? I am using 3.5 SP1, Linq to SQL
sjnaughton
All-Star
27391 Points
5485 Posts
MVP
Re: Show Field But Do Not Allow Editing
Jan 16, 2010 08:45 AM|LINK
Hi Zhili, have a look at these articles here : Making a Field Read-Only via the ReadOnlyAttribute – Dynamic Data and Making Individual Tables Read Only – Dynamic Data
Dynamic Data ReadOnly Attribute
Always seeking an elegant solution.
san2
Member
4 Points
2 Posts
Re: Show Field But Do Not Allow Editing
Jun 04, 2013 01:01 AM|LINK
I know this is an old post but just want to update it with another solution in case it helps others. In place of the [ReadOnly(true)] attribute, you can use the [Editable(false)] attribute on the field you want to display but not allow edits on. If you annotate an Entity Reference (i.e. foreign key relationship) with the ReadOnly or Editable attribute, the editable dropdown list on the Edit page gets replaced with a hyperlink.