Click here to Skip to main content
15,913,486 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
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]
C#
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;
    }
}
Posted
Updated 6-May-14 3:11am
v2
Comments
Manas Bhardwaj 6-May-14 8:47am    
any effort?
Devino_M 6-May-14 8:49am    
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;

}
}
Thanks7872 6-May-14 8:55am    
You are suppose to mention all these things in question itself. Still its not clear what issue you are facing with this code?
Darshan.Pa 6-May-14 8:56am    
first describe, how you want it , server side or client side?

1 solution

C#
// If implemented implicitly (first option above):

string error = this[columnName];

See some solutions from below
msdn[^]
Validating User Input [^]
 
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