FormView: no Update inside Run-at-Server Table control

I am not sure whether this behavior is documented somewhere, so I simply tell you from my recent programming adventure😉

In a FormView, I usually arrange the controls inside EditItemTemplate in a table. In this particular case, only selected fields should be edited, depending on some kind of status information.

Since each field (plus prompt) occupies a single row in the table, my choice was straightforward to declare the dynamic table rows as

<tr runat="server" id="trSomething">

However, the form behaved strangely, namely it did not retrieve the control values bound with Bind() into the UpdateCommand’s parameter collection.

To debug, I added Updated and Updating events to the SqlDataSource, and a ItemUpdating event to the FormView, where the NewValues collection of FormViewUpdateEventArgs always gave me an empty dictionary.

I dug further into the generated code somewhere below the Temporary ASP.Net Files directory, and found that no code was generated to retrieve the control values into a dictionary, which should happen during a Bind in Update.

Then I realized that somehow a control bound for update must never be inside any other control marked as Run As Server Control. And indeed, removing the runat tag resolved the mystery.

So if you have controls inside a FormView which are to be displayed or hidden depending the state of a record, you have to hide or display them one by one, as rearranging tables dynamically will break your database functionality.

5 Responses to FormView: no Update inside Run-at-Server Table control

  1. Michal says:

    just sample, how it works for me:

    Estimate Price:

    <asp:TextBox ID=”TextBoxEstimatePrice” runat=”server” Columns=”8″ Text=”>


    HtmlControl panelStart = (HtmlControl)FormView1.FindControl(“PanelStart”);
    panelStart.Visible = false;

    HtmlControl panelEnd = (HtmlControl)FormView1.FindControl(“PanelEnd”);
    panelEnd.Visible = false;

  2. Michal says:

    so, once again:

    <panel id=”PanelStart” runat=”server”>
    <td align=”right”>
    Estimate Price:</td>
    <asp:TextBox ID=”TextBoxEstimatePrice” runat=”server” Columns=”8″ Text='<%# Bind(“EstimatedPrice”) %>’></asp:TextBox>
    <panel id=”PanelEnd” runat=”server”>

    HtmlControl panelStart = (HtmlControl)FormView1.FindControl(“PanelStart”);
    panelStart.Visible = false;

    HtmlControl panelEnd = (HtmlControl)FormView1.FindControl(“PanelEnd”);
    panelEnd.Visible = false;

  3. Michal says:

    damn, i hate this intelligent editors

  4. loti says:

    My solution:

    public partial class foo : System.Web.UI.Page
    public string GetVisibility(int id)
    string name = “Custom” + id.ToString().Trim();
    if (ConfigurationSettings.AppSettings[name] == “true”)
    return “visible”;
    return “collapse”;

    protected void Page_Load(object sender, EventArgs e)


    <tr style="visibility:”>
    <asp:Label ID="Custom1Label" runat="server" Text="” />
    <asp:TextBox ID="Custom1TextBox" runat="server" Text='’

    <tr style="visibility:”>
    <asp:Label ID="Custom2Label" runat="server" Text="” />
    <asp:TextBox ID="Custom2TextBox" runat="server" Text='’


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: