I am trying to validate data after updating the data in a Details View. I can access and update the database without any problems, but to validate,...

How It Works

Get an answer in three easy steps. Here's how it works...

Ask Your Question

1. Ask Your Question

Enter your programming question at the top of this page and click Get An Answer.

Pick Your Priority

2. Pick Your Priority

Tell us how quickly you want your programming question answered.

Get An Answer

3. Get An Answer

Connect with your programmer via online chat or telephone call.

Answer

Customer

I am trying to validate data after updating the data in a Details View. I can access and update the database without any problems, but to validate, I have added a compare validator in the edit template (header template) for the start date and end date fields on a table. I have chosen the end date as the control to validate and the start date as the value to compare. Since these are databound controls, I am using "Bind" instead of "eval". Here is the code:

ControlToCompare='<%# Bind("ContractStartDate", "{0}") %>'
ControlToValidate='<%# Bind("Contract
EndDate", "{0}") %>'
ErrorMessage="CompareValidator"
ValueToCompare='<%# Bind("Contract_StartDate") %>' Text="*">

I am getting this error: "Unable to find control id '02/06/2010' referenced by the 'ControlToCompare' property of 'CompareValidator1' ". This is one of the start dates on the table. Is there a way to find the control id? Should I be using and OLEDB connection in code instead?

Thanks

Posted
Matthew Pomar
Programmer

stuartcrome,

Thanks for your question. The values of the ControlToCompare attribute should be the ID of the control, no the value of the control. The error seams to indicate you are trying to pass the value as the ID.

The ID of the control you are trying to validate is in the market. Is should look something like:

<input id="MyControlId" type="textbox" runat="sever" />

"MyControlId" is the IS you need to enter into ControlToCompare.

I hope this answers your question. If it does, please be sure to accept it by click the Accept Answer button below this answer. If you have any followup questions, please post them here.

Best Regards,
Matthew Pomar

Posted
Customer

Well, this is an ASP.NET control that was pulled in from the toolbox. There are no assigned IDs in the markup, which is the source of my confusion. Here is the markup for the Details View container:

BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataKeyNames="Contract_ID" DataSourceID="SqlDataSource1"
GridLines="Vertical" style="z-index: 1; left: 565px; top: 359px; position: absolute; height: 75px; width: 384px">

And here is the markup for the databound controls:

SortExpression="Contract_StartDate" />
SortExpression="Contract_EndDate" />

Do I need to add IDs to the controls?

Posted
Matthew Pomar
Customer Support

stuartcrome,

When posting your code, could you please make sure to format it with the code toolbar button? (it has the 101010) characters.

Every control must have a unique ID. If it doesn't have one by default, you should add one. I'm surprised the page compiles without it. Can you post the entire page (make sure to highlight it then click the code button)?

Regards,
Matthew Pomar

Posted
Customer

I see my markup got truncated here because of the brackets. Here is the markup for the controls without brackets:

asp:BoundField DataField="ContractStartDate" HeaderText="ContractStartDate" SortExpression="Contract_StartDate"

asp:BoundField DataField="ContractEndDate" HeaderText="ContractEndDate" SortExpression="Contract_EndDate"

Thanks,

Posted
Matthew Pomar
Customer Support

Thanks, but I really need to see the complete page. Can you post the entire page (make sure to highlight it then click the code button)?

Regards,
Matthew Pomar

Posted
Customer

OK, here is the aspx page markup (part 1):

enter code here

`<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewContract.aspx.cs" Inherits="NewContract" %>

    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; New Contract </center>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConflictDetection="CompareAllValues" 
    ConnectionString="<%$ ConnectionStrings:ConnectionString13 %>" 
    DeleteCommand="DELETE FROM [tblContracts] WHERE [Contract_ID] = ? AND [Vendor_ID] = ? AND [Acct_EmpID] = ? AND [Buyer_ID] = ? AND [Unit_ID]        = ? AND [Bank_ContactID] = ? AND [Programmer_ID] = ? AND [Contract_StartDate] = ? AND [Contract_EndDate] = ? AND [Contract_Number] = ? AND         [Contract_HourlyRate] = ? AND [Contract_FeeMax] = ? AND [Contract_Description] = ? AND [Contract_Date] = ? AND [Contract_Status] = ?" 
    InsertCommand="INSERT INTO [tblContracts] ([Contract_ID], [Vendor_ID], [Acct_EmpID], [Buyer_ID], [Unit_ID], [Bank_ContactID],      [Programmer_ID], [Contract_StartDate], [Contract_EndDate], [Contract_Number], [Contract_HourlyRate], [Contract_FeeMax], 

[ContractDescription], [ContractDate], [ContractStatus]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
OldValuesParameterFormatString="original
{0}"
ProviderName="<%$ ConnectionStrings:ConnectionString13.ProviderName %>"
SelectCommand="SELECT * FROM [tblContracts]"
UpdateCommand="UPDATE [tblContracts] SET [VendorID] = ?, [AcctEmpID] = ?, [BuyerID] = ?, [UnitID] = ?, [BankContactID] = ?, [ProgrammerID] = ?, [ContractStartDate] = ?, [ContractEndDate] = ?, [ContractNumber] = ?, [ContractHourlyRate] = ?, [ContractFeeMax] = ?, [ContractDescription] = ?, [ContractDate] = ?, [ContractStatus] = ? WHERE [ContractID] = ? AND [VendorID] = ? AND [AcctEmpID] = ? AND [BuyerID] = ? AND [UnitID] = ? AND [BankContactID] = ? AND [ProgrammerID] = ? AND [ContractStartDate] = ? AND [ContractEndDate] = ? AND [ContractNumber] = ? AND [ContractHourlyRate] = ? AND [ContractFeeMax] = ? AND [ContractDescription] = ? AND [ContractDate] = ? AND [ContractStatus] = ?">




















































AutoGenerateColumns="False" BackColor="White" BorderColor="#999999"
BorderStyle="None" BorderWidth="1px" CellPadding="3" DataKeyNames="Contract
ID"
DataSourceID="SqlDataSource1" GridLines="Vertical"

    style="z-index: 1; left: 385px; top: 360px; position: absolute; height: 54px; width: 145px" 
    onselectedindexchanged="GridView1_SelectedIndexChanged">
    <RowStyle BackColor="#EEEEEE" ForeColor="Black" Font-Names="Arial, Verdana" Font-Size="Small"/>
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="Contract_ID" HeaderText="Contract_ID" 
            InsertVisible="False" ReadOnly="True" SortExpression="Contract_ID" />
    </Columns>
    <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#777777" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#777777" Font-Bold="True" Font-Names="Arial, Verdana" ForeColor="White" />
    <AlternatingRowStyle BackColor="#DCDCDC" />
</asp:GridView>
Posted
Customer

And, here is the part 2. Sorry for dividing this up, but I got a message saying the comment has be between 8 and 10,000 characters.

Thanks,

Stuart

enter code here

BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" DataKeyNames="Contract_ID" DataSourceID="SqlDataSource1"
GridLines="Vertical" style="z-index: 1; left: 565px; top: 359px; position: absolute; height: 75px; width: 384px">




InsertVisible="True" ReadOnly="True" SortExpression="Contract_ID" />
SortExpression="Vendor_ID" />
SortExpression="Acct_EmpID" />
SortExpression="Buyer_ID" />
SortExpression="Unit_ID" />
SortExpression="Bank_ContactID" />
SortExpression="Programmer_ID" />
SortExpression="Contract_StartDate" />
SortExpression="Contract_EndDate" />
SortExpression="Contract_Number" />
HeaderText="Contract_HourlyRate" SortExpression="Contract_HourlyRate" />
SortExpression="Contract_FeeMax" />
HeaderText="Contract_Description" SortExpression="Contract_Description" />
SortExpression="Contract_Date" />
SortExpression="Contract_Status" />


    <EditRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
    <AlternatingRowStyle BackColor="#DCDCDC" />
</asp:DetailsView>

</form>
<div id="confirm">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>


Posted
mahmud
Programmer

stuartcrome,

Thanks for your question.

Seems problem is here:

ControlToCompare='<%# Bind("ContractStartDate", "{0}") %>'
ControlToValidate='<%# Bind("ContractEndDate", "{0}") %>'

Please check that if your textbox has any id attribute. If not provide one. and then change the above code as

ControlToCompare='IDOfTheTextBoxToCompare'
ControlToValidate='IDOfTheTextBoxToValidate'

I hope this answers your question. If it does, please be sure to accept it by click the Accept Answer button below this answer. If you have any followup questions, please post them here.

Best Regards,
Mahmud

Posted
Customer

Thanks for your answer Mahmud. However, these are controls inside an ASP.NET DetailsView. If I add an ID to the control I get this parser error message:

Type 'System.Web.UI.WebControls.BoundField' does not have a public property named 'ID'. I'm currently trying another solution to this issue, but if you have other suggestions, please feel free to respond.

Thanks,

Stuart

Posted
Matthew Pomar
Customer Support

Stuart,

I see that another Expert posted a similar answer. I don't know if any of this helps you. I am having real difficulty piecing all of your code together.

When troubleshooting these kind of problems, I often go to my sandbox/playground environment and great a simplified version of the issue. This eliminates external factors and allows me to focus on the issue. If you can, would you please do the same. Create a simple example illustrating the problem, then paste the code in a comment for me. Make sure to highlight the entire code block then click the format code toolbar button.

You can use the preview below the textarea to verify that all of your code is highlighted.

Regards,
Matthew Pomar

Posted
Customer

Hello Matthew,

I will accept your answer due to your persistence and patience with this issue. I have found another solution for this issue using OLE Db. This is my first time using this site and I didn't realize there were problems with using Internet Explorer 9 when posting code. That is why my code was so jumbled. Thanks for your help.

Posted

quoteTestimonialsquote

About ExpertHelp

ExpertHelp is changing the way you connect with service professionals.

Whether you have a quick question while preparing your taxes, troubleshooting a computer problem, or need to hire an attorney, ExpertHelp is the most convenient and affordable way to connect with the right service professional to get the job done.

ExpertHelp has been in business since 2011, is an A+ Rated Better Business Bureau accredited member, and offers a 100% satisfaction guarantee on every question you ask!

More Programming Questions...

Ask Your Programming Question & Get An Answer Now!