Click here to Skip to main content
15,850,750 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I want to compare pervious value to current values of same textbox in

Another option is to store the data in viewstate.


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm6.aspx.cs" Inherits="PracticeWeb.WebForm6" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:TextBox ID="TextBox1" runat="server" Width="200px"></asp:TextBox>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Click to Compare" />

Code Behind

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PracticeWeb
    public partial class WebForm6 : System.Web.UI.Page
        protected void Page_PreRender(object sender, EventArgs e)
        protected void Page_Load(object sender, EventArgs e)
            if (Page.IsPostBack)
                string strPrev = Convert.ToString(ViewState["PrevValue"]);
                if (strPrev.Equals(TextBox1.Text))
                    Response.Write("Not Equal");
Share this answer
Store the value in somewhere then compare, here an example using hidden field
Compare Old and New Text of TextBox[^]
Share this answer
1. Store in database
2. Use hidden field for the previous value
3. Compare the hiddenfield value with current one ..
Share this answer
Save your value in hidden field
and compare on postback.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900