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

Posted on 2011-05-06
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
    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.

    LVL 3

    Expert Comment

    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

    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?
    LVL 33

    Accepted Solution

    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
    Note that Session will persist from page to page, whereas ViewState is only good until the user navigates to another page.
    LVL 3

    Expert Comment

    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;      

    LVL 3

    Expert Comment

    DataTable dataTableInfo= new DataTable();

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

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now