Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm not sure the purpose of Recipient class. Anyhow, you want to instantiate Recipient list before adding a recipient.</p> <p><img src="https://i.stack.imgur.com/Ilk2Q.jpg" alt="enter image description here"></p> <pre><code>&lt;asp:TextBox runat="server" ID="txtFName" /&gt;&lt;br /&gt; &lt;asp:Button runat="server" ID="btnEnter" Text="Submit" OnClick="btnEnter_Click" /&gt;&lt;br /&gt; &lt;asp:Label runat="server" ID="lblFName" /&gt;&lt;br /&gt; &lt;asp:Label runat="server" ID="lblFName1" /&gt;&lt;br /&gt; &lt;asp:Label runat="server" ID="lblFName2" /&gt;&lt;br /&gt; &lt;asp:Label runat="server" ID="lblFName3" /&gt;&lt;br /&gt; &lt;asp:Label runat="server" ID="lblFName4" /&gt;&lt;br /&gt; [Serializable] public class Recipient { public string name { get; set; } } public List&lt;Recipient&gt; recipientList { get { if (ViewState["recipientList"] != null) return (List&lt;Recipient&gt;)ViewState["recipientList"]; return new List&lt;Recipient&gt;(); } set { ViewState["recipientList"] = value; } } protected void btnEnter_Click(object sender, EventArgs e) { List&lt;Recipient&gt; recipient = recipientList; recipient.Add(new Recipient{ name = txtFName.Text.Trim()}); recipientList = recipient; int count = recipient.Count; if (count == 1) lblFName.Text = recipientList[0].name; if (count &gt; 1) lblFName1.Text = recipientList[1].name; if (count &gt; 2) lblFName2.Text = recipientList[2].name; if (count &gt; 3) lblFName3.Text = recipientList[3].name; if (count &gt; 4) lblFName4.Text = recipientList[4].name; } </code></pre>
    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.
    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