如何创建用于保存和验证的C#Asp.Net按钮? [英] How Do I Create An C# Asp.Net Button For Save And Validate?

查看:92
本文介绍了如何创建用于保存和验证的C#Asp.Net按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


有人可以帮助我。



我试图在visual Studio上按一下按钮。 />
按钮将是一个保存按钮,但我也希望按钮进行验证。



i希望在验证未完成时禁用保存按钮,当验证完成后,用户必须能够保存数据。



即时通讯使用Visual Studio 2013,C#ASP.NET



谢谢





  public   string   [ string  columnName] 
{
get
{
Result = ;
if (columnName == FirstName
{
if String .IsNullOrEmpty(FirstName) )
{
结果= 请输入名字;
}
}
else if (columnName == LastName
{
if String .IsNullOrEmpty(LastName))
{
Result = 请输入姓氏;
}
}
else if (columnName == 地址
{
if String .IsNullOrEmpty(Address))
{
Result = 请输入地址;
}
}
else if (columnName == 城市
{
if String .IsNullOrEmpty(City))
{
Result = 请输入城市;
}
}
else if (columnName == 状态
{
if (State == 选择
{
结果= 请选择州;
}
}
else if (columnName == Zip
{
if String .IsNullOrEmpty(Zip))
{
Result = 请输入zip;
}
else if (Zip.Length < 6
{
结果= Zip的长度必须至少为6位!;
}
else
{
bool zipNumber = Regex.IsMatch(Zip, @ ^ [0-9] * $);
if (zipNumber == false
{
Result = 请仅输入zip中的数字;
}
}
}
其他 如果( columnName == IsValid
{
Result = 的ToString();
}

return 结果;
}
}

解决方案

);
if (zipNumber == false
{
Result = 请仅输入zip中的数字;
}
}
}
else if (columnName == IsValid
{
Result = true .ToString();
}

返回结果;
}
}


< blockquote>

  //  如果隐式实现(上面的第一个选项): 

str ing error = this [columnName];



查看下面的一些解决方案

msdn [ ^ ]

验证用户输入 [ ^ ]

hi
could someone please assist me.

im trying to do a button on visual Studio.
the button will be a save button but i also want the button to do validation.

i want the save button to be disabled if validation not complete, and when validation is complete, user must be able to save the data.

im using Visual Studio 2013, C# ASP.NET

Thank You

[EDIT - OP code from comment]

public string this[string columnName]
{
    get
    {
        Result = null;
        if (columnName == "FirstName")
        {
            if (String.IsNullOrEmpty(FirstName))
            {
                Result = "Please enter first name";
            }
        }
        else if (columnName == "LastName")
        {
            if (String.IsNullOrEmpty(LastName))
            {
                    Result = "Please enter last name";
            }
        }
        else if (columnName == "Address")
        {
            if (String.IsNullOrEmpty(Address))
            {
                Result = "Please enter Address";
            }
        }
        else if (columnName == "City")
        {
            if (String.IsNullOrEmpty(City))
            {
                Result = "Please enter city";
            }
        }
        else if (columnName == "State")
        {
            if (State == "Select")
            {
                Result = "Please select state";
            }
        }
        else if (columnName == "Zip")
        {
            if (String.IsNullOrEmpty(Zip))
            {
                Result = "Please enter zip";
            }
            else if (Zip.Length < 6)
            {
                Result = "Zip's length has to be at least 6 digits!";
            }
            else
            {
                bool zipNumber = Regex.IsMatch(Zip, @"^[0-9]*$");
                if (zipNumber == false)
                {
                    Result = "Please enter only digits in zip";
                }
            }
        }
        else if (columnName == "IsValid")
        {
            Result = true.ToString();
        }

        return Result;
    }
}

解决方案

"); if (zipNumber == false) { Result = "Please enter only digits in zip"; } } } else if (columnName == "IsValid") { Result = true.ToString(); } return Result; } }


// If implemented implicitly (first option above):

string error = this[columnName];


See some solutions from below
msdn[^]
Validating User Input [^]


这篇关于如何创建用于保存和验证的C#Asp.Net按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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