将文本框值与 [英] compare textbox values with
本文介绍了将文本框值与的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在asp.net中将先前值与同一文本框的当前值进行比较
I want to compare pervious value to current values of same textbox in asp.net
推荐答案
另一种选择是将数据存储在viewstate中.
ASPX代码
Another option is to store the data in viewstate.
ASPX Code
<%@ 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
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");
}
}
}
}
将值存储在某个地方然后进行比较,这里是使用隐藏字段的示例
比较文本框的旧文本和新文本 [
Store the value in somewhere then compare, here an example using hidden field
Compare Old and New Text of TextBox[^]
1.存储在数据库中
2.使用隐藏字段作为上一个值
3.将hiddenfield值与当前值进行比较..
1. Store in database
2. Use hidden field for the previous value
3. Compare the hiddenfield value with current one ..
这篇关于将文本框值与的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文