How to save the dynamically created textbox values temporarily in the client side

Posted on 2011-05-06
Medium Priority
Last Modified: 2012-05-11
I have dynamically created textboxes and I am able to save the values entered in the textbox into the database.but I would like to save these values in temporarily in the client side who enters the value in the textbox.How can I achieve this?
Question by:asudhaa
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35705032
Not sure I got your question correctly.

You can store the avlues in Cookies (when storing to database ).cookies are stored on client machiun.
then access the values from cookies.


Expert Comment

ID: 35705184
you can save value in List  object that has key and value
key would be useId and value woulde be textbox.value

if there are 2 or more textboxes so make a class oject that contain all the value and use id
and store that class object ya list object in Session , viewstate , cokkies
any where u want.

Author Comment

ID: 35705741
this my code in view state  

protected override void LoadViewState(object earlierState)
            int count = 1;
            if (ViewState["dynamictable"] == null)
            CreateDynamicTable(count, count);

how can I save the values in values in view state?
should i do this in page load?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 33

Accepted Solution

Todd Gerbert earned 2000 total points
ID: 35711212
I would just use the Session - this will store the values in whatever location your web.config defines.

Alternatively, you can use the ViewState - this will store the values in a hidden form field on the page.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
	protected void Page_Init(object sender, EventArgs e)
		TextBox tb;

		tb = new TextBox();
		tb.ID = "TextBox1";

		textBoxesDiv.Controls.Add(new Literal() { Text = "<br />" });

		tb = new TextBox();
		tb.ID = "TextBox2";

    protected void Page_Load(object sender, EventArgs e)

	protected void SaveButton_Click(object sender, EventArgs e)
		// Use Session
		Session["TextBox1Value"] = ((TextBox)FindControl("TextBox1")).Text;
		// Use ViewState
		ViewState["TextBox2Value"] = ((TextBox)FindControl("TextBox2")).Text;
	protected void LoadButton_Click(object sender, EventArgs e)
		string tb1Val = "NOT SET";
		string tb2Val = "NOT SET";

		// Retrieve from session
		if (Session["TextBox1Value"] != null)
			tb1Val = (string)Session["TextBox1Value"];

		if (ViewState["TextBox2Value"] != null)
			tb2Val = (string)ViewState["TextBox2Value"];

		resultsDiv.InnerHtml = String.Format(
			"Text box 1: {0}<br />Text box 2: {1}",
			tb1Val, tb2Val);

Open in new window

LVL 33

Expert Comment

by:Todd Gerbert
ID: 35711219
Note that Session will persist from page to page, whereas ViewState is only good until the user navigates to another page.

Expert Comment

ID: 35737406
I agree it depend on requirement.

yes you have to create viewstate on page load or page_init
     -- Make property of viewsate (get n set )
intiliaze it any where u want during any prcoess
and use it.  

  ---  for creation dyanmic table
DataTable dt = new DataTable();
  ---- u made simple structure of your dynamic table
  ViewSate["ZXY"] = dt;

Loading of DataTable
 --thats depend on you who u populate the dataTable  
 --  suppose ur loadviewSate(); return dataTable
      ViewSate["ZXY"] = dt;      


Expert Comment

ID: 35737438
DataTable dataTableInfo= new DataTable();

queueList.OrderStatus = _orderStatusId;
dataTableInfo= orderList.GetOrdersByStatus;

GridView1.DataSource = dataTableInfo;
// Throw the results into view state for sorting
ViewState["ViewStateOrderStatus"] = dataTableInfo

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question