Two-way Data-Binding with FormView control

Two-way Data-Binding with FormView control

Old forum URL: forums.lhotka.net/forums/t/6575.aspx


SonOfPirate posted on Saturday, March 07, 2009

HELP!  I am completely stumped at this point and hope another set of eyes can help identify what is going wrong...

I have an ASP.NET page with a FormView control bound to a CslaDataSource.  The following is what I have for the InsertItemTemplate:

<table class="FormTable" width="100%">
  <tr>
    <td class="FormLabel">
      <
label for="ItemNumberTextBox">
        <span class="RequiredField">
          <asp:Literal ID="ItemNumberLabel" runat="server"
                              
Text="<%$ Resources:Strings, ItemNumber_Caption %>" />
        </span>
      </label
>
   
</td
>
   
<td class="FormBody" valign
="top">
     
<table border="0" cellpadding="0" cellspacing
="0">
       
<tr
>
         
<td
>
           
<asp:TextBox ID="ItemNumberTextBox" runat="server" MaxLength="50" TabIndex="1"
                                   
Text='<%# Bind("ItemNumber") %>'
/>
         
</td
>
         
<td
>
           
<asp:ImageButton ID="LookupButton" runat="server" SkinID="LookupButton" TabIndex="2"
/>
         
</td
>
       
</tr
>
     
</table
>
     
<asp:RequiredFieldValidator ID="ItemNumberValidator" runat="server" Enabled
="false"
                                                      
 ControlToValidate="ItemNumberTextBox" CssClass
="FormValidation"
                                                      
 Display="Dynamic" ErrorMessage="Please enter a valid Item Number."
/>
   
</td
>
 
</tr><tr
>
   
<td class
="FormLabel">
     
<label for
="DescriptionTextBox">
       
<span
>
         
<asp:Literal ID="DescriptionLabel" runat="server"
                              
Text="<%$ Resources:Strings, Description_Caption %>"
/>
       
</span
>
     
</label
>
   
</td
>
   
<td class="FormBody" valign
="top">
     
<asp:Label ID="DescriptionTextBox" runat="server" Text='<%# Eval("Description") %>'
/>
   
</td
>
 
</tr><tr
>
   
<td class
="FormLabel">
     
<label for
="AliasTextBox">
       
<span class
="RequiredField">
         
<asp:Literal ID="AliasLabel" runat="server" Text="<%$ Resources:Strings, Alias_Caption %>"
/>
       
</span
>
     
</label
>
   
</td
>
   
<td class="FormBody" valign
="top">
     
<asp:TextBox ID="AlternateNumberTextBox" runat="server" MaxLength="50" TabIndex="3"
                              
Text='<%# Bind("AlternateNumber") %>' /><br
/>
     
<asp:RequiredFieldValidator ID="AlternateNumberValidator" runat="server" Enabled="false"
                                                       
 ControlToValidate="AlternateNumberTextBox" CssClass="FormValidation"
                                                       
 Display="Dynamic" ErrorMessage="Please enter a valid Alternate Number." />
   
</td>
 
</tr><tr>
   
<td class="FormFooter" colspan="2">&nbsp;</td>
 
</tr>
</table>

The EditItemTemplate and ItemTemplate are basically the same - with the obvious changes for Bind versus Eval.

In the SelectObject handler, I check for an id value in the url and, if present, call the Get method on my BO; otherwise, I call the New method to create a new, empty instance.  When the page posts back, I use the FormView's CurrentMode property to determine if I need to call the InsertItem() or UpdateItem() method .  In the InsertObject and UpdateObject handlers, I use the DataMapper to copy the field values into the BO.  All of this should be pretty standard and is how the sample ProjectTracker app works.

My problem is that the Values collection is empty when the form is posted back.  I know this is usually because something is wrong with my FormView markup, but I can't find anything wrong.  I have verified that the data is present in the Request.Form collection, so it is being passed back to the server.  It appears that the FormView control is simply not willing or able to pull the field values from the data when posted back.

Does anyone have any idea what is wrong with the above markup or anything else that might be preventing my app from behaving correctly?

 

JoeFallon1 replied on Monday, March 09, 2009

Viewstate usually affects things like this. Is it disabled?

Joe

 

SonOfPirate replied on Tuesday, March 10, 2009

From what I can tell, it is enabled.  I am able to see the form field values being passed back by looking into the Request.Form collection when the page is submitted.  They are there but the FormView won't pick them up.

 

jhelak replied on Friday, September 03, 2010

I am having the same issue. Did you ever find a resolution?

Thanks

Copyright (c) Marimer LLC