Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing the same template for edit and insert in a list view
    primarykey
    data
    text
    <p>I am using WebForms .NET 4.5 and a asp:ListView and model binding. Within that I am using the:</p> <pre><code>&lt;EditItemTemplate&gt; &lt;InsertItemTemplate&gt; </code></pre> <p>to define the appearance of the control. However 99% of the time these layouts are identical. Is there a way to use one for both INSERT and EDIT? Or is there another approach where I can define the HTML once and use it in either?</p> <p>I am not using <code>&lt;asp:DynamicControl&gt;</code> but normal <code>&lt;asp:texbox&gt;</code> etc. so I don't believe <a href="https://stackoverflow.com/questions/13282869/net-4-5-webforms-do-i-still-really-have-to-specify-all-3-templates-in-a-form?rq=1">.NET 4.5 WebForms: do I (still) really have to specify all 3 templates in a FormView?</a> applies.</p> <p>I have already tried a user control. And while the content gets included the model binding is broken in that no new values are applied to the object being inserted / edited.</p> <p><strong>SOLUTION UPDATE</strong>:</p> <p>Declaring a form view without the INSERT TEMPLATE:</p> <pre><code> &lt;asp:FormView ID="fvData" runat="server" ItemType="DataLayer.Models.Country" DataKeyNames="Id" InsertMethod="InsertRecord" SelectMethod="BindData" UpdateMethod="UpdateRecord" OnDataBound="fvData_DataBound"&gt; &lt;EditItemTemplate&gt; &lt;b&gt;EDIT&lt;/b&gt; &lt;div class="row"&gt; &lt;div class="form-group"&gt; &lt;label class="col-md-4 control-label" for="txtCountryName"&gt;Name&lt;/label&gt; &lt;div class="col-md-8"&gt; &lt;asp:TextBox runat="server" ID="txtCountryName" name="txtCountryName" placeholder="My Country" CssClass="form-control" Text='&lt;%#: BindItem.Name %&gt;'&gt;&lt;/asp:TextBox&gt; &lt;dav:DataAnnotationsValidator CssClass="label label-danger" ID="davSchoolName" runat="server" ValidationGroup="Default" MetadataSourceID="msCountryInformation" ControlToValidate="txtCountryName" ObjectProperty="Name" Display="Dynamic" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/EditItemTemplate&gt; &lt;/asp:FormView&gt; </code></pre> <p>and then:</p> <pre><code>protected void Page_Init() { if (!IsPostBack) { fvData.InsertItemTemplate = fvData.EditItemTemplate; } } </code></pre> <p>and there you are using the EDIT template for INSERT as well.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload