---
title: "Why Data is not posted in asp.net  using postback?"  
description: "Why Data is not posted in asp.net  using postback?"  
author: "Anonymous User"  
published: 2014-10-05  
updated: 2014-10-05  
canonical: https://www.mindstick.com/forum/2305/why-data-is-not-posted-in-asp-dot-net-using-postback  
category: "asp.net"  
tags: ["c#", "asp.net"]  
reading_time: 2 minutes  

---

# Why Data is not posted in asp.net  using postback?

I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to post [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science) to the same [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page) after [postback](https://www.mindstick.com/blog/342/postback-in-asp-dot-net) with the help of [ViewState](https://www.mindstick.com/blog/326/viewstate-in-asp-dot-net). I fill out the contents of the page and post the [form](https://www.mindstick.com/forum/6/multi-form-mfc-application) and display the [input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) on the same page but the [validator](https://www.mindstick.com/forum/156905/what-is-data-annotation-validator-attribute-in-asp-dot-net-mvc) says that the [firstname](https://www.mindstick.com/interview/33973/how-to-split-the-full-name-into-firstname-and-lastname-in-sql-server) cannot be null while I just filled out the [textbox](https://www.mindstick.com/forum/12714/dynamic-textbox-in-gridview) before I submitted the form.

```
<asp:Content ContentPlaceHolderID="Main" runat="server" EnableViewState="true">    <form id="form1" runat="server">    <div>        <table>            <tr>                <td>                    <asp:Label ID="lbl1" Text="First Name" runat="server" />                </td>                <td>                 <asp:TextBox ID="tFirstName" runat="server" />            </td>            <td>                <asp:RequiredFieldValidator ControlToValidate="tFirstName" ErrorMessage="This field cannot be empty."                    runat="server" />            </td>        </tr>        <tr>            <td>                <asp:Label ID="lbl2" Text="Last Name" runat="server" />            </td>            <td>                <asp:TextBox ID="tLastName" runat="server" />            </td>        </tr>                </table></div><asp:Button ID="id" Text="Submit" runat="server" OnClick="Submit" /><div>    <p>        <asp:Label ID="lTest" runat="server" /></p></div><asp:Label ID="lSubmit" runat="server" /></form>
```

**\**

**.cs code:**

```
protected void Page_Load(object sender, EventArgs e)        {            if (Page.IsPostBack)            {                tFirstName.Text = (string)ViewState["tFirstName"];                tLastName.Text = (string)ViewState["tLastName"];            }            else            {                ViewState["tFirstName"] = tFirstName.Text;                ViewState["tLastName"] = tLastName.Text;            }        }         protected void Submit(object sender, System.EventArgs args)        {            try            {                lTest.Text = tFirstName.Text + " " tLastName.Text;            }            catch (Exception ex)            {                 throw;            }        }
```

## Replies

### Reply by Anonymous User

try this code:

```
if (!Page.IsPostBack){     tFirstName.Text = (string)ViewState["tFirstName"];     tLastName.Text = (string)ViewState["tLastName"];}
```


---

Original Source: https://www.mindstick.com/forum/2305/why-data-is-not-posted-in-asp-dot-net-using-postback

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
