Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Fetching value from textbox dyanamically

Fetching value from textbox dyanamically

Scheduled Pinned Locked Moved ASP.NET
databasehelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ashutosh_karna
    wrote on last edited by
    #1

    I have a web form with a table control. No. of columns & no. of rows are asked by user and table is generated with cells filled with textboxes dynamically. The id of textboxes are generated dynamically. User enters the values in textboxes in table & click calculate button, on which I want to supply a set of results based on input data. Can anybody tell me how to fetch the value entered in a textbox at runtime. I am using following code. public void CreateTableRawData(int rows) { for (int i = 0; i < rows; i++) { TableRow tr = new TableRow(); TableCell td = new TableCell(); TextBox txt = new TextBox(); td.Controls.Add(txt); txt.ID = "txt" + i.ToString(); tr.Cells.Add(td); Table1.Rows.Add(tr); Table1.Caption = "Raw Data Form"; } } protected void Button2_Click(object sender, EventArgs e) { int rows = Convert.ToInt32(TextBox_rows.Text.ToString()); double[] data = new double[rows]; string [] dataText = new string[rows]; Table tbl = (Table)Panel1.FindControl("Table1"); for (int i = 0; i < rows; i++) { data[i] = Convert.ToDouble(Table1.Rows[i].Cells[0].Text.ToString()); } data[0] = Convert.ToDouble(Table1.Rows[0].Cells[0].ToString()); Label lbl = new Label(); double sum = DistributionFitting.Statistics.Sum(data); lbl.Text = sum.ToString(); } I am getting following error at runtime. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index

    B A 2 Replies Last reply
    0
    • A ashutosh_karna

      I have a web form with a table control. No. of columns & no. of rows are asked by user and table is generated with cells filled with textboxes dynamically. The id of textboxes are generated dynamically. User enters the values in textboxes in table & click calculate button, on which I want to supply a set of results based on input data. Can anybody tell me how to fetch the value entered in a textbox at runtime. I am using following code. public void CreateTableRawData(int rows) { for (int i = 0; i < rows; i++) { TableRow tr = new TableRow(); TableCell td = new TableCell(); TextBox txt = new TextBox(); td.Controls.Add(txt); txt.ID = "txt" + i.ToString(); tr.Cells.Add(td); Table1.Rows.Add(tr); Table1.Caption = "Raw Data Form"; } } protected void Button2_Click(object sender, EventArgs e) { int rows = Convert.ToInt32(TextBox_rows.Text.ToString()); double[] data = new double[rows]; string [] dataText = new string[rows]; Table tbl = (Table)Panel1.FindControl("Table1"); for (int i = 0; i < rows; i++) { data[i] = Convert.ToDouble(Table1.Rows[i].Cells[0].Text.ToString()); } data[0] = Convert.ToDouble(Table1.Rows[0].Cells[0].ToString()); Label lbl = new Label(); double sum = DistributionFitting.Statistics.Sum(data); lbl.Text = sum.ToString(); } I am getting following error at runtime. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index

      B Offline
      B Offline
      Brij
      wrote on last edited by
      #2

      ashutosh_karna wrote:

      System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

      As exception shows,you must be accessing some array's index that doesn't hold.Debug it ,you'll be able to get the problem

      Cheers!! Brij Check My Latest Article

      1 Reply Last reply
      0
      • A ashutosh_karna

        I have a web form with a table control. No. of columns & no. of rows are asked by user and table is generated with cells filled with textboxes dynamically. The id of textboxes are generated dynamically. User enters the values in textboxes in table & click calculate button, on which I want to supply a set of results based on input data. Can anybody tell me how to fetch the value entered in a textbox at runtime. I am using following code. public void CreateTableRawData(int rows) { for (int i = 0; i < rows; i++) { TableRow tr = new TableRow(); TableCell td = new TableCell(); TextBox txt = new TextBox(); td.Controls.Add(txt); txt.ID = "txt" + i.ToString(); tr.Cells.Add(td); Table1.Rows.Add(tr); Table1.Caption = "Raw Data Form"; } } protected void Button2_Click(object sender, EventArgs e) { int rows = Convert.ToInt32(TextBox_rows.Text.ToString()); double[] data = new double[rows]; string [] dataText = new string[rows]; Table tbl = (Table)Panel1.FindControl("Table1"); for (int i = 0; i < rows; i++) { data[i] = Convert.ToDouble(Table1.Rows[i].Cells[0].Text.ToString()); } data[0] = Convert.ToDouble(Table1.Rows[0].Cells[0].ToString()); Label lbl = new Label(); double sum = DistributionFitting.Statistics.Sum(data); lbl.Text = sum.ToString(); } I am getting following error at runtime. System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        Try to debug your application and check which line is throwing the exception. check the index of the array. One more important thing, you are creating the textboxes runtime. You need to create the textbox before Page_load(). Because in ASP.NET Page life cycle, ViewState Data and PostBack data loads just before the Pageload. So if you create any control after page load you can't restore the postback and view state data. The best option, try to create your controls in Page_PreInit() Event.

        cheers, Abhijit CodeProject MVP Web Site:abhijitjana.net View My Recent Article

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups