Note that there are some explanatory texts on larger screens.

plurals
  1. POFormView.FindControl works for one form but not the other on the same page
    primarykey
    data
    text
    <p>I have two Formviews on the same page. I can use FindControl on the first without issue, but it always fails on the second one.</p> <p>I am using the ItemTemplate for both, both default to ReadOnly, both are bound to SQLDataSources (different ones) but I cannot for the life of me work out why FindControl works for one and not the other.</p> <p>I have removed a lot of the plain text from the code below.</p> <pre><code>&lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:SoftSaleDBConnectionString %&gt;" SelectCommand="SELECT * FROM [Apps] WHERE ([AppID] = @AppID)" &gt; &lt;SelectParameters&gt; &lt;asp:FormParameter FormField="AppID" Name="AppID" Type="Int32" /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; &lt;asp:FormView ID="FormView1" runat="server" DataKeyNames="AppID" DataSourceID="SqlDataSource1"&gt; &lt;ItemTemplate&gt; &lt;h1&gt; &lt;asp:Label ID="AppNameLabel" runat="server" Text='&lt;%# Bind("AppName") %&gt;' /&gt; &lt;asp:Label ID="VersionLabel" runat="server" Text='&lt;%# Bind("Version") %&gt;' /&gt; for &lt;asp:Label ID="OSLabel" runat="server" Text='&lt;%# Bind("OS") %&gt;' /&gt; &lt;/h1&gt; &lt;p&gt;Text here&lt;/p&gt; &lt;p&gt;&lt;asp:TextBox ID="LicenseTextBox" runat="server" Text='&lt;%# Eval("License")%&gt;' TextMode="MultiLine" Width="800px" Rows="25" ReadOnly="True"&gt;&lt;/asp:TextBox&gt;&lt;/p&gt; &lt;asp:HiddenField ID="AppLocation" runat="server" ViewStateMode="Inherit" Value='&lt;%# Bind("AppLocation") %&gt;'/&gt; &lt;/ItemTemplate&gt; &lt;/asp:FormView&gt; &lt;p&gt;&lt;asp:Literal ID="SizeLiteral" runat="server"&gt;&lt;/asp:Literal&gt;&lt;/p&gt; &lt;asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="&lt;%$ ConnectionStrings:SoftSaleDBConnectionString %&gt;" SelectCommand="SELECT * FROM [Installations] WHERE (([AppID] = @AppID) AND ([Username] = @Username))" &gt; &lt;SelectParameters&gt; &lt;asp:FormParameter FormField="AppID" Name="AppID" Type="Int32" /&gt; &lt;asp:FormParameter FormField="Username" Name="Username" Type="String" /&gt; &lt;/SelectParameters&gt; &lt;/asp:SqlDataSource&gt; &lt;asp:FormView ID="DLFormView" runat="server" DataSourceID="SqlDataSource4" DataKeyNames="AppID,Username"&gt; &lt;ItemTemplate&gt; &lt;p&gt; &lt;asp:Label ID="DLAppNameLabel" runat="server" /&gt; &lt;br /&gt; &lt;br /&gt; &lt;asp:Label ID="NumberOfInstallations" runat="server" Text='&lt;%# Bind("Installations") %&gt;'&gt;&lt;/asp:Label&gt; &lt;br /&gt; &lt;asp:HiddenField ID="TotalInstallations" runat="server" /&gt; Number of New Installations: &lt;asp:DropDownList ID="NumberOfNewInstallations" runat="server"&gt; &lt;/asp:DropDownList&gt; &lt;br /&gt; &lt;asp:Label ID="TotalNumberOfInstallations" runat="server" Text="Label"&gt;&lt;/asp:Label&gt; &lt;/p&gt; &lt;/ItemTemplate&gt; &lt;/asp:FormView&gt; </code></pre> <p>And the FindControl coding is as follows...</p> <pre><code>TextBox LicTextBox = (TextBox)FormView1.FindControl("LicenseTextBox"); HiddenField AppLocCode = (HiddenField)FormView1.FindControl("AppLocation"); Label AppNameCode = (Label)FormView1.FindControl("AppNameLabel"); </code></pre> <p>These always work...</p> <pre><code>Label DLAppNameCode = (Label)DLFormView.FindControl("DLAppNameLabel"); </code></pre> <p>This always returns null. I've read a million bosts about the controls not being rendered until databinding has completed, but surely if the two FOrmViews are set up the same way, the result should be the same.</p> <p>Any help would be much apreciated :)</p> <p>Matt :)</p>
    singulars
    1. This table or related slice is empty.
    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.
    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