I have an entity set of NotificationTemplates, and each one of these has a collection of zero-many SmsTemplate entities. When editing or viewing a NotificationTemplate, I have a link to View SMS Templates
. That link takes me to a List view for the SmsTemplates entity set, filtered for the NotificationTemplate I was viewing.
How can I prevent the user changing this filter to show SmsTemplates for another NotificationTemplate? That is, I want the filter, but it must be read only. The drop-down just mustn't drop down, it must just display the name of the NotificationTemplate that these SmsTemplates belong to. To view SmsTemplates for another NotificationTemplate, the user must click View SMS Templates
from that other template.
The code-behind of the filter template is what tells the filter to pick up its value from the query string. It checks the DefaultValue property, and if set to a value, assigns that to the filter. What you want to do is add logic that makes the filter read-only when DefaultValue has a value . The simplest way to make it read-only this is to make the control disabled. Here's how you would do it for the default ForeignKey.ascx.cs implementation:
protected void Page_Init(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (!Column.IsRequired)
{
DropDownList1.Items.Add(new ListItem("[Not Set]", NullValueString));
}
PopulateListControl(DropDownList1);
// Set the initial value if there is one
string initialValue = DefaultValue;
if (!String.IsNullOrEmpty(initialValue))
{
DropDownList1.SelectedValue = initialValue;
DropDownList1.Enabled = false;
}
}
}