I have a project where the user has to input a range of questions along with the question numbers. (So the number of questions is not fixed.) I am using a panel where i am adding the dynamically created textboxes. The textboxes are created with the user clicks an image button.
So far so good.
now i want to store the questions entered by the user in a databaase, how can i achieve this?
Also if the user creates and enters the data in the textbox, and later when he returns, i wld like to show the data previuosly entered by him, how can i achive this?
Thank in advance

Dani AI

Generated

Given 's scenario (a variable number of question textboxes created by clicking an image button) and the pointers from and , a reliable pattern is to treat each question as a persistent record and keep UI state separate from storage. The main choices are a normalized table for queryable data or a single JSON column for quick persistence. The following covers a cross-platform workflow, a simple schema, and common pitfalls.

A practical table design:

CREATE TABLE questions (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT NOT NULL,
  form_id INT DEFAULT NULL,
  q_index INT NOT NULL,
  text TEXT NOT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  UNIQUE KEY ux_user_form_index (user_id, form_id, q_index)
);

Save / restore workflow (platform-agnostic):

  • When the form is submitted (or on an AJAX autosave), send the current ordered list of question texts and an identifier for the form/user.
  • On the server, upsert rows keyed by (user_id, form_id, q_index) so edits update rather than duplicate.
  • To render a returning user’s form, load rows ordered by q_index and generate the inputs in the same order. If client-side code creates inputs, it should recreate them from the loaded dataset rather than relying on previously rendered DOM.

Platform notes and troubleshooting:

  • For ASP.NET dynamic controls must be recreated on every postback early in the page lifecycle (Page_Init) using a persisted count or saved metadata; failing to do this causes lost values and events.
  • For PHP/HTML flows using input arrays (or JSON payloads) keeps server parsing simple.
  • Always use prepared statements, transactions for multi-row updates, and validate/trim input. Consider JSON storage for simple apps, but use normalized rows when searching, indexing, or partial updates are needed.

Recommended Answers

All 2 Replies

set the Name property of the textboxes to a common name and increment with numbers, for example, "txtQuestion1", "txtQuestion2", etc.

Then later you can iterate through the Controls collection (through the Form or whatever is holding the textboxes) and if the name starts with "txtQuestion" for example, take it's Text value and store it.

To load the values just do the process backwards, setting the Text property to "txtQuestion" boxes (or as you create them).

Hope that helps a bit

Hi, Also try DataGridView Control to add the Questions and Answer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.