473,394 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

textbox value retrive

Hi,
Here the below code is for dynamically creating textboxs, its creating fine but after user enters some values in textboxs how can i retrive that values?
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using System.Collections.Generic;
  11.  
  12. public partial class _Default : System.Web.UI.Page
  13. {
  14.  
  15.    static  int a = 0;
  16.    int skillCount = 0;
  17.    List<string> skillControlList;
  18.    int yearsUsedCount = 0;
  19.    List<string> yearsUsedControlList;
  20.    int yearsLastUsedCount = 0;
  21.    List<string> YearsLastUsedUsedControlList;
  22.  
  23.  
  24.    protected override void LoadViewState(object savedState)
  25.    {
  26.       base.LoadViewState(savedState);
  27.       skillControlList = (List<string>)ViewState["skillControlList"];
  28.       foreach (string skillYearsId in skillControlList)
  29.       {
  30.  
  31.           skillCount++;
  32.           TextBox skillTxt = new TextBox();
  33.           skillTxt.ID = skillYearsId;
  34.           //LiteralControl lineBreak = new LiteralControl("<br />");
  35.           TableRow tr = new TableRow();
  36.           TableCell tc = new TableCell();
  37.           tc.Controls.Add(skillTxt);
  38.           tr.Cells.Add(tc);
  39.           tblSkills.Rows.Add(tr);
  40.  
  41.       }
  42.       yearsUsedControlList = (List<string>)ViewState["yearsUsedControlList"];
  43.       foreach (string yearsUsedId in yearsUsedControlList)
  44.       {
  45.  
  46.           yearsUsedCount++;
  47.           TextBox yearsUsedTxt = new TextBox();
  48.           yearsUsedTxt.ID = yearsUsedId;
  49.         //  LiteralControl lineBreak1 = new LiteralControl("<br />");
  50.           TableRow row = new TableRow();
  51.           TableCell cell = new TableCell();
  52.           cell.Controls.Add(yearsUsedTxt);
  53.           row.Cells.Add(cell);
  54.           tblYearsUsed.Rows.Add(row);
  55.  
  56.       }
  57.       YearsLastUsedUsedControlList = (List<string>)ViewState["YearsLastUsedUsedControlList"];
  58.       foreach (string yearsLastUsedId in YearsLastUsedUsedControlList)
  59.       {
  60.  
  61.           yearsLastUsedCount++;
  62.           TextBox yearsLastUsedTxt = new TextBox();
  63.           yearsLastUsedTxt.ID = yearsLastUsedId;
  64.           //  LiteralControl lineBreak1 = new LiteralControl("<br />");
  65.           TableRow yearRow = new TableRow();
  66.           TableCell yearCell = new TableCell();
  67.           yearCell.Controls.Add(yearsLastUsedTxt);
  68.           yearRow.Cells.Add(yearCell);
  69.           tblYearsLastUsed.Rows.Add(yearRow);
  70.  
  71.       }
  72.    }
  73.  
  74.  
  75.    protected void Page_Load(object sender, EventArgs e)
  76.    {
  77.       if (!IsPostBack)
  78.       {
  79.          skillControlList = new List<string>();
  80.          ViewState["skillControlList"] = skillControlList;
  81.          yearsUsedControlList = new List<string>();
  82.          ViewState["yearsUsedControlList"] = yearsUsedControlList;
  83.          YearsLastUsedUsedControlList = new List<string>();
  84.          ViewState["YearsLastUsedUsedControlList"] = YearsLastUsedUsedControlList;
  85.          a = 0;
  86.       }
  87.    }
  88.  
  89.    protected void addControlButton_Click(object sender, EventArgs e)
  90.    {
  91.        a++;
  92.        int b = 10;
  93.        if (a <= b)
  94.        {
  95.            skillCount++;
  96.            TextBox skillTxt = new TextBox();
  97.            //skillTxt.Text = "a new text Box";
  98.            skillTxt.ID = "txtSkill" + skillCount.ToString();
  99.            // LiteralControl lineBreak = new LiteralControl("<br />");
  100.            TableRow tr = new TableRow();
  101.            TableCell tc = new TableCell();
  102.            tc.Controls.Add(skillTxt);
  103.            tr.Cells.Add(tc);
  104.            tblSkills.Rows.Add(tr);
  105.            skillControlList.Add(skillTxt.ID);
  106.            ViewState["skillControlList"] = skillControlList;
  107.  
  108.  
  109.            yearsUsedCount++;
  110.            TextBox yearsUsedTxt = new TextBox();
  111.            //yearsUsedTxt.Text = "a new text Box";
  112.            yearsUsedTxt.ID = "txtYearUsed" + yearsUsedCount.ToString();
  113.            // LiteralControl lineBreak1 = new LiteralControl("<br />");
  114.            TableRow row = new TableRow();
  115.            TableCell cell = new TableCell();
  116.            cell.Controls.Add(yearsUsedTxt);
  117.            row.Cells.Add(cell);
  118.            tblYearsUsed.Rows.Add(row);
  119.            yearsUsedControlList.Add(yearsUsedTxt.ID);
  120.            ViewState["yearsUsedControlList"] = yearsUsedControlList;
  121.  
  122.            yearsLastUsedCount++;
  123.            TextBox yearsLastUsedTxt = new TextBox();
  124.            //yearsUsedTxt.Text = "a new text Box";
  125.            yearsLastUsedTxt.ID = "txtLastYearUsed" + yearsLastUsedCount.ToString();
  126.            // LiteralControl lineBreak1 = new LiteralControl("<br />");
  127.            TableRow yearRow = new TableRow();
  128.            TableCell yearCell = new TableCell();
  129.            yearCell.Controls.Add(yearsLastUsedTxt);
  130.            yearRow.Cells.Add(yearCell);
  131.            tblYearsLastUsed.Rows.Add(yearRow);
  132.            YearsLastUsedUsedControlList.Add(yearsLastUsedTxt.ID);
  133.            ViewState["YearsLastUsedUsedControlList"] = YearsLastUsedUsedControlList;
  134.  
  135.  
  136.        }
  137.        else
  138.        {
  139.            Label1.Text = "no more";
  140.        }
  141.  
  142.            }    
  143.    }
May 20 '08 #1
1 1616
Frinavale
9,735 Expert Mod 8TB
Have you seen the article on how to use dynamic controls in ASP.Net?

-Frinny
May 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: TattyMane bigpond.net.au> | last post by:
asp.net, visual studio 2003, IE6 I have a sample web page that is linked to another page. On the first page, I have a text box, on the second, the first page's text box text is displayed using a...
5
by: Fox | last post by:
foreach (TextBox tb in this.Controls) MessageBox.Show(tb.Name); //Error Occur for non-textBox, i.e. Button Thank
2
by: utterberg | last post by:
Can anyone help me with this problem? I dynamically creates several textboxes using a placeholder. This works fine. But is there a way for me to loop through theese textboxes and retrive its value...
4
by: khyati30 | last post by:
hi, i am working on asp i am facing problem in asp , combox i want to retrive data in textbox , from combobox . in combobox , when i select particular user , i want to fetch that regarding...
1
idsanjeev
by: idsanjeev | last post by:
hello i wants to retrive data in textarea like input text but in textarea value is not work so what should be use to retrive textarea value after any error <input type="text" name="name"...
1
by: abirami elango | last post by:
Hi, i have created a web application in vb.net. i have assigned a value to the textbox during page UNLOAD event as below.. ......... Protected Sub Page_Unload(ByVal sender As Object, ByVal e As...
2
by: zimbu | last post by:
Hi all, I have created some textboxes dynamically by using var sun = document.createElement('input'); with button click. after some time I will re visit the fields, how do I retrive that...
1
by: vaniKanabathy | last post by:
I need to call back what i had write in notepad using vb application. I can do it using the coding below but the problem is i want to retrive the value in different textbox but all the values in...
3
by: buterfly0707 | last post by:
hi evryone.. i want to get the text box value to list box . And also i want this textbox value enter into the dabasex table called Area and @ th esame time insert this value to List box. here is...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.