Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to save value of dynamically added textboxes into database in asp.net??
please help me



thanx
Posted

You need to re-create your dynamic controls on (every) post-back if you want to refer them. Use Page_Init or Page_Load event.
Reference Link :- How to save values of dynamically added textboxes into database in asp.net[^]
 
Share this answer
 
Comments
soniya sangal 22-Sep-11 4:41am    
sorry i didnot get on that site can u explain me
i hv done like.........
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
string strValue = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnAddTitle_Click(object sender, EventArgs e)
{

NumberOfControls += 1;
}

private void CreateTextBoxes()
{

for (int counter = 0; counter <= NumberOfControls; counter++)
{
TextBox tb = new TextBox();
tb.Width = 150;
tb.Height = 18;
tb.TextMode = TextBoxMode.SingleLine;
tb.ID = "TextBoxID" + (counter + 1).ToString();
// add some dummy data to textboxes
//tb.Text = "Enter Title " + counter;
phTextBoxes.Controls.Add(tb);
phTextBoxes.Controls.Add(new LiteralControl("<br/>"));

}

}
protected override void CreateChildControls()
{
// Here we are recreating controls to persist the ViewState on every post back
if (Page.IsPostBack)
{
NumberOfControls += 1;
CreateTextBoxes();
}
else
{
CreateTextBoxes();
// Increase the control value to 1
NumberOfControls = 0;
}

}
public int NumberOfControls
{
get
{
if (ViewState["Count"] == null)
{
return 0;
}
return (int)ViewState["Count"];
}
set
{
ViewState["Count"] = value++;
}
}



}
soniya sangal 22-Sep-11 4:42am    
nw how ta store all textbox value into database
You'll need to use the FindControl method, something like this:

C#
var textBox = FindControl("<id_of_textbox>") as TextBox;

if(textBox != null)
{
    var textBoxValue = ((TextBox)textBox).Text;
}

</id_of_textbox>


More on the FindControl method:

http://msdn.microsoft.com/en-us/library/486wc64h.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900