i want to add 10 strings in array and i have one textbox in that am going to add new array that need to be added as 11 string onclick of show button then again 12 string again it should be added to that 11 strings...and so on... how to do this??
am sharing what i have tried..
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="arrytxt.aspx.cs" Inherits="Validators.Examples.arrytxt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtNewText" runat="server"></asp:TextBox>
<asp:Label ID="lblResultingText" runat="server" ForeColor="#CC0099" ></asp:Label>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="btnAdd_Click" />
<asp:Button ID="btnShow" runat="server" Text="Show" OnClick="btnShow_Click" />
</div>
</form>
</body>
</html>
Code behind::using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
namespace Validators.Examples
{
public partial class arrytxt : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private List<string> ResultArray
{
get
{
if (Session["resultArray"] == null)
Session["resultArray"] = new List<string>();
return (List<string>)Session["resultArray"];
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
ResultArray.Add(txtNewText.Text);
txtNewText.Text = string.Empty;
}
protected void btnShow_Click(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
foreach (string s in ResultArray)
{
sb.Append("<br />" + s);
}
lblResultingText.Text = sb.ToString();
}
}
}