473,320 Members | 1,820 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,320 software developers and data experts.

How to create and collect textbox value at runtime?

115 100+
Hi All

I am create textbox and collect textbox value at runtime using c#

my aspx code
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7.     <title>Untitled Page</title>
  8. </head>
  9. <body>
  10.     <form id="form1" runat="server">
  11.     <div>
  12.         <asp:Button ID="Button1" runat="server" Text="Add More" OnClick="Button1_Click" />
  13.         <asp:Panel ID="Panel1" runat="server">
  14.             <asp:Table ID="Table1" runat="server">
  15.                 <asp:TableRow>
  16.                     <asp:TableCell>Language</asp:TableCell>
  17.                     <asp:TableCell>Read</asp:TableCell>
  18.                     <asp:TableCell>Write</asp:TableCell>
  19.                     <asp:TableCell>Speak</asp:TableCell>
  20.  
  21.                 </asp:TableRow>
  22.  
  23.             </asp:Table>
  24.         </asp:Panel>
  25.  
  26.     </div>
  27.     </form>
  28. </body>
  29. </html>
my cs code

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11.  
  12. public partial class test : System.Web.UI.Page
  13. {
  14.  
  15.     //
  16.     //System.Web.UI.WebControls.TextBox txt1 = new System.Web.UI.WebControls.TextBox();
  17.  
  18.     protected void Page_Load(object sender, EventArgs e)
  19.     {
  20.         //Panel1
  21.         if (!IsPostBack)
  22.         {
  23.             ViewState["count"] = 0;
  24.         }
  25.         else
  26.         {
  27.            // gettextcheckboxval();
  28.         }
  29.  
  30.     }
  31.     protected void Button1_Click(object sender, EventArgs e)
  32.     {
  33.         gettextcheckboxval();
  34.  
  35.         ViewState["count"] = Convert.ToInt32(ViewState["count"])+1;
  36.         //Response.Write(Convert.ToString(ViewState["count"]));
  37.  
  38.         for (int i = 0; i < Convert.ToInt32(ViewState["count"]); i++)
  39.         {
  40.  
  41.  
  42.             TableRow tr = new TableRow();
  43.             TableCell td1 = new TableCell();
  44.             TableCell td2 = new TableCell();
  45.             TableCell td3 = new TableCell();
  46.             TableCell td4 = new TableCell();
  47.  
  48.             TextBox textBoxes = new TextBox();
  49.             textBoxes.ID = "TextBox" + i;
  50.             textBoxes.Text = "English";
  51.  
  52.  
  53.             CheckBox readchk = new CheckBox();
  54.             readchk.ID = "readCheckBox" + i;
  55.  
  56.             CheckBox writechk = new CheckBox();
  57.             writechk.ID = "writeCheckBox" + i;
  58.  
  59.             CheckBox speakchk = new CheckBox();
  60.             speakchk.ID = "speakCheckBox" + i;
  61.  
  62.             td1.Controls.Add(textBoxes);
  63.             td2.Controls.Add(readchk);
  64.             td3.Controls.Add(writechk);
  65.             td4.Controls.Add(speakchk);
  66.  
  67.             tr.Cells.Add(td1);
  68.             tr.Cells.Add(td2);
  69.             tr.Cells.Add(td3);
  70.             tr.Cells.Add(td4);
  71.  
  72.             Table1.Rows.Add(tr);
  73.  
  74.  
  75.             //Panel1.Controls.Add(txt);
  76.         }
  77.     }
  78.  
  79.     private void gettextcheckboxval()
  80.     {
  81.         for (int i = 0; i < Convert.ToInt32(ViewState["count"]); i++)
  82.         {
  83.             TextBox txtCtrl = (TextBox)Panel1.FindControl("TextBox" + (i + 1));
  84.             if (txtCtrl != null)
  85.             {
  86.  
  87.                 Response.Write((i+1)+" box value = "+txtCtrl.Text);
  88.                 Response.Write("<br>");
  89.             }
  90.             else
  91.             {
  92.                 Response.Write("TextBox"+(i+1)+" not found");
  93.                 Response.Write("<br>");
  94.             }
  95.         }
  96.     }
  97. }
  98.  
but my output

TextBox1 not found
TextBox2 not found

what is wrong with my code

Pls guide me

Thanks in Advance
Mar 2 '11 #1
0 1532

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

Similar topics

0
by: Mark | last post by:
All, Excuse the re-post but I have found something which works for the UserID but not for the Password (see previous post below). The problem is I don't understand how it works and therefore...
1
by: pepsi330ml | last post by:
I need to create a crosstab report that does not need the user to know the total number to columns and manually add a new textbox and amend the VBA code. The VBA code should handle everything from...
3
by: cql90 | last post by:
Hi all PRO, I don't know how to create the MSAccess database in the runtime with C#, Are there any body know how to do this? I am pretty sure that all of you know how to do it, except me :( ....
0
by: Carl Mercier | last post by:
Hi, I am trying to resize a textbox at runtime depending on the browser but for whatever reason, the textbox is not resized. It stays at the original size. How can I do what I want? Here's...
3
by: Ricardo Corsi P. Cesar | last post by:
Hi, i looking for example in asp.net (VB) to make the RegularExpressionValidator in runtime in my code behind. I found some similars codes, but nothing in VB.. thanks!
2
by: John | last post by:
Hi all, I thought that this would be very basic. Basically, I have a textbox set at type password. When I try to set the value of this textbox at runtime the text field does not get populated. I...
1
by: RockNRoll | last post by:
I'm new to ASP.NET and need to filter a datagrid based on a textbox value. I have a working datagrid and would like the WHERE part of my SQL statement to call the value of a textbox and refresh...
2
by: Raed Sawalha | last post by:
Hi, This is probably pretty simple but... I am dynamically adding rows to a HtmlTable that contain Textbox controls. (There may be more than one server control/textbox in a given cell) How...
1
by: tina2626 | last post by:
how can i pass textbox value to gridview using C#.net at runtime not using database values. i m hving textbox1 and gridview1. can anyone suggest me to do this coding in ASP.NET(C# language).
5
by: divyasrinivasan | last post by:
hi how to add MULTIPLE TEXTBOX at runtime using CLASS FILE i tried using this code for creating textbox but it did not work textbox t=new textbox(); t.id="mytextbox"; panel p=new panel();...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.