比较asp.net中的标签和文本框值 [英] compare the lable and text box value in asp.net

查看:113
本文介绍了比较asp.net中的标签和文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

plz
任何人都可以告诉我
如何在asp.net中比较文本框和标签值

plz
anyone can tell me
how we can compare the text box and lable value in asp.net

推荐答案

if (TextBox1.Text == Label1.Text)
            {
                //Do Something.
            }
            else
            {
                //Do Something if not equals
            }


它们都是控件,因此在将id和runat="server"属性添加到标签控件中后,您只需在代码后面执行TextBox.Text == Label.Text标记.
They are both controls, so you could just do a TextBox.Text == Label.Text in your code-behind after adding the id and runat="server" attributes to the label control in your markup.


您应该使用Equals来比较两个字符串,这也是指定StringComparison选项的一种好习惯.
阅读此以获取更多信息:
在.NET Framework中使用字符串的最佳做法 [
You should use Equals to compare both Strings, and it''s also a good practice to specify the StringComparison options.

Read this for more info:
Best Practices for Using Strings in the .NET Framework[^]

if(TextBox.Text.Equals(Label.Text, StringComparison.Ordinal))
{
  //Values are equal
}
else
{
  //Values are not equal
}



希望对您有帮助



Hope it helps


这篇关于比较asp.net中的标签和文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆