Click here to Skip to main content
15,923,789 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 asp.net
Posted

Another option is to store the data in viewstate.

ASPX Code

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm6.aspx.cs" Inherits="PracticeWeb.WebForm6" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" Width="200px"></asp:TextBox>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Click to Compare" />
    </div>
    </form>
</body>
</html>


Code Behind

C#
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)
        {
            ViewState.Add("PrevValue",TextBox1.Text);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                string strPrev = Convert.ToString(ViewState["PrevValue"]);
                if (strPrev.Equals(TextBox1.Text))
                    Response.Write("Equal");
                else
                    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