The good news is that I am now able to display the Password field in the GridView (List.aspx). Since this field is binary (byte[]) in the database and DD does not have support for binary data, I have created a new FieldTemplate called Binary.ascx. Here is
the code.
I use a UIHint in the domain service metadata class to use the new binary control.
[UIHint("Binary")] public byte[] Password { get; set; }
Binary.ascx
<%@ Control Language="C#" CodeBehind="Binary.ascx.cs" Inherits="MarsUserManager.BinaryField" %>
<asp:Literal runat="server" ID="Literal1"/>
Binary.ascx.cs
public partial class BinaryField : FieldTemplateUserControl
{
public override Control DataControl
{
get
{
return Literal1;
}
}
}
Please note that I have removed the override string FieldValueString from the because I seem not to need it in there. Instead I have used the
FieldValue to set the value of the Literal control.
1 - Is this all right? Please correct me if I am wrong.
This seems to be working well.
The problem starts with the Edit.aspx. I have created a Binary_Edit.ascx to display the Password binary field when in edit mode. I display it in a text box for editing:
Binary_Edit.ascx
<%@ Control Language="C#" CodeBehind="Binary_Edit.ascx.cs" Inherits="MarsUserManager.BinaryEditField" %>
List of validation errors
•The data has been deleted in the underlying store.
•The data has been deleted in the underlying store.
Password: aaa111 The data has been deleted in the underlying store.
I would appreciate very much if someone could help me to sort this out. I could send my whole project if someone is willing and kind to have a look at it if it is easier that way.
pallone
Member
165 Points
160 Posts
Re: CustomPages not working CONTINUED and Continuing
Feb 16, 2012 04:01 PM|LINK
Hi,
I have good news and bad news.
The good news is that I am now able to display the Password field in the GridView (List.aspx). Since this field is binary (byte[]) in the database and DD does not have support for binary data, I have created a new FieldTemplate called Binary.ascx. Here is the code.
I use a UIHint in the domain service metadata class to use the new binary control.
[UIHint("Binary")]
public byte[] Password { get; set; }
Binary.ascx
<%@ Control Language="C#" CodeBehind="Binary.ascx.cs" Inherits="MarsUserManager.BinaryField" %>
<asp:Literal runat="server" ID="Literal1"/>
Binary.ascx.cs
public partial class BinaryField : FieldTemplateUserControl
{
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
if (this.FieldValue == null)
{
return;
}
Literal1.Text = MarsUserManager.Utils.Tools.DecryptPassword((byte[])FieldValue).Replace("\0", "");
}
//public override string FieldValueString
//{
// ....
//
//}
public override Control DataControl
{
get
{
return Literal1;
}
}
}
Please note that I have removed the override string FieldValueString from the because I seem not to need it in there. Instead I have used the FieldValue to set the value of the Literal control.
1 - Is this all right? Please correct me if I am wrong.
This seems to be working well.
The problem starts with the Edit.aspx. I have created a Binary_Edit.ascx to display the Password binary field when in edit mode. I display it in a text box for editing:
Binary_Edit.ascx
<%@ Control Language="C#" CodeBehind="Binary_Edit.ascx.cs" Inherits="MarsUserManager.BinaryEditField" %>
<asp:TextBox ID="TextBox1" runat="server" CssClass="DDTextBox"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1" CssClass="DDControl DDValidator" ControlToValidate="TextBox1" Display="Static" Enabled="false" />
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1" CssClass="DDControl DDValidator" ControlToValidate="TextBox1" Display="Static" Enabled="false" />
<asp:DynamicValidator runat="server" ID="DynamicValidator1" CssClass="DDControl DDValidator" ControlToValidate="TextBox1" Display="Static" />
<asp:DomainValidator runat="server" ID="DomainValidator1" CssClass="DDControl DDValidator" Display="Static" />
Binary_Edit.ascx.cs
public partial class BinaryEditField : FieldTemplateUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (Column.MaxLength < 20)
{
TextBox1.Columns = Column.MaxLength;
}
TextBox1.ToolTip = Column.Description;
SetUpValidator(RequiredFieldValidator1);
SetUpValidator(RegularExpressionValidator1);
SetUpValidator(DynamicValidator1);
this.SetUpDomainValidator(DomainValidator1);
SetUpValidator(DomainValidator1);
}
protected override void OnDataBinding(EventArgs e)
{
base.OnDataBinding(e);
if (Column.MaxLength > 0)
{
TextBox1.MaxLength = Math.Max(FieldValueEditString.Length, Column.MaxLength);
}
var temp = MarsUserManager.Utils.Tools.DecryptPassword((byte[])FieldValue).Replace("\0", "");
TextBox1.Text = temp;
}
protected override void ExtractValues(IOrderedDictionary dictionary)
{
//dictionary[Column.Name] = ConvertEditedValue(TextBox1.Text);
dictionary[Column.Name] = MarsUserManager.Utils.Tools.EncryptPassword(TextBox1.Text);
}
public override Control DataControl
{
get
{
return TextBox1;
}
}
}
}
I have also created a tblUser_Edit.ascx web control under the EntityTemplates folder so that I can limit the fields to display for editing:
tblUser_Edit.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="tblUser_Edit.ascx.cs" Inherits="MarsUserManager.DynamicData.EntityTemplates.tblUser_Edit" %>
<tr>
<td>Name: </td>
<td><asp:DynamicControl Mode="Edit" runat="server" DataField="FirstName" ID="fname" ></asp:DynamicControl></td>
</tr>
<tr>
<td>Password: </td>
<td>
<asp:DynamicControl Mode="Edit" runat="server" DataField="Password" ID="DynamicControl3" />
</td>
</tr>
tblUser_Edit.ascx.cs
public partial class tblUser_Edit : System.Web.DynamicData.EntityTemplateUserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
The password is shown in the text box fine.
However, when I click the update link button in the Edit.aspx page I get an error straight away and an asterisk beside the Password text box:
List of validation errors
•The value is not valid.
Password: aaa111 *
2 - I cannot figure out what is wrong. Can someone shed some light?
I have tried commenting out the SetUpValidator method in the Binary_Edit.ascx.cs to see if I could see a better error message
//SetUpValidator(RequiredFieldValidator1);
//SetUpValidator(RegularExpressionValidator1);
//SetUpValidator(DynamicValidator1);
//this.SetUpDomainValidator(DomainValidator1);
//SetUpValidator(DomainValidator1);
I got this error:
List of validation errors
•The data has been deleted in the underlying store.
•The data has been deleted in the underlying store.
Password: aaa111 The data has been deleted in the underlying store.
I would appreciate very much if someone could help me to sort this out. I could send my whole project if someone is willing and kind to have a look at it if it is easier that way.
Cheers
C