Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate Dynamic Textbox and Get values
    primarykey
    data
    text
    <p>I want to create dynamic text box when user click on Add more link button. For this I am using this code. And I have to mention that I am using master page.</p> <pre><code> protected void lnkAddMore_Click(object sender, EventArgs e) { if (Request.Cookies["value"] != null) { i = Convert.ToInt32(Request.Cookies["value"].Value) + 1 ; } for (int k = 1; k &lt;= i; k++) { LiteralControl literal = new LiteralControl(); literal.Text = "&lt;br /&gt;&lt;br /&gt;"; Label newLabel = new Label(); newLabel.Text = "Choice" + " " + k.ToString(); newLabel.ID = "lblChoice_" + k.ToString(); newLabel.Attributes.Add("runat", "Server"); this.panelLabel.Controls.Add(newLabel); this.panelLabel.Controls.Add(literal); LiteralControl literal1 = new LiteralControl(); literal1.Text = "&lt;br /&gt;&lt;br /&gt;"; TextBox nexText = new TextBox(); nexText.ID = "txtChoice_" + k.ToString(); nexText.Attributes.Add("TextMode", "MultiLine"); nexText.Attributes.Add("runat", "Server"); panelTextbox.Controls.Add(nexText); this.panelTextbox.Controls.Add(literal1); Response.Cookies["value"].Value = i.ToString(); Session["Panel"] = panelTextbox; } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["Panel"] != null) { ContentPlaceHolder content=new ContentPlaceHolder(); content.Controls.Add(Session["Panel"] as Panel); } } } </code></pre> <p>Now I am facing trouble how to retrieve the data of the these text boxes after the clicking on the submit button so that I can store the values of there text boxes to database.</p> <p>What will be code written for the click event of btnSave</p> <pre><code> protected void btnSave_Click(object sender, EventArgs e) { if (Session["Panel"] != null) { ContentPlaceHolder content_new = new ContentPlaceHolder(); for (int i = 1; i &lt;= count; i++) { strControlName = "txtChoice_" + i.ToString(); TextBox objTextBox = (TextBox)content_new.FindControl(strControlName); strTextBoxValues[i] = objTextBox.Text; string str3 = strTextBoxValues[2]; } } } </code></pre> <p>This code is showing error for objTextBox. The error is NullReferenceException.</p> <p>How to write stored procedure for saving data of above code?</p> <p>The main problem is handling the parameter declaration, how to declare dynamic parameter for passing values so that value is saved for dynamic textbox?</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload