473,597 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create and collect textbox value at runtime?

115 New Member
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 1583

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

Similar topics

0
2425
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 cannot update it to do as I need. Could someone explain A) how to modify this to make sure the username & password are valid or B) How the below works so I can do it myself. I have never seen "PARAMETERS" used before in SQL which has thrown me...
1
8471
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 getting the total number of col and create the exact number of textbox. Tat's is, the user only need to ran this report and tat's it. http://support.microsoft.com/default.aspx?scid=kb;en-us;328320 This information from msdn is only dynamic when...
3
2731
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 :( . Thanks you so much in advance, I am deeply appreciated for your help. Take care and have a good one... Kate
0
1339
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 the code I have in my web user control: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
3
3789
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
1674
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 thought I could just go ========= txtPassword.Text = "MyPassword" ========= If I do this, nothing appears in the textbox at all.
1
2222
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 the datagrid when a button is clicked. SELECT RateMatrix.Name, RateMatrix., RateMatrix.EC, RateMatrix., RateMatrix. FROM RateMatrix WHERE (. <= TEXTBOX_VALUE_GOES_HERE)
2
3869
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 do I get the value of a textbox when the form is posted back? I would expect something like:
1
7201
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
2308
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(); p.controls.add(t); i want it using class file pls help its very urgent...
0
7971
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7893
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8381
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8040
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3889
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3932
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1495
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.