• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

server side validation

i have a checkbox that I do validationwheather it is checked or not at the server side , by button click, so if user hits the button without checking it, it display message, so than user checks but that message still stays there doesnt dissapear what I need to do for that?
0
1jaws
Asked:
1jaws
  • 5
  • 3
2 Solutions
 
sunithnairCommented:
Are you using a validation control or just a label to show the error message?
0
 
1jawsAuthor Commented:
label.
0
 
1jawsAuthor Commented:
because i check in see if that user inside the database, it is i display message you are already in the database...as a label..
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sunithnairCommented:
Ok then in your pageload event always make the label visible=false and then in the evnt that you check the database and show the label make it visible=true
Page Load
 
lblError.Visible = false;
 
Other Event
 
lblError.Text = "Error message";
lblError.Visible = true;

Open in new window

0
 
1jawsAuthor Commented:
I am confused..I have this code  if checkbox is not checked i display this message, ok, so what I need to do? I did make lblcheckterms visible false at the properties, and put lblcheckterms. visible true here in this code but didnt work..
if (chkAgreeToTerms.Checked == false)
        {
             
            lblcheckterms.Text = "Check agreement to continue";
            return;
        }
0
 
prairiedogCommented:
Server-side validation will not fire until the page is submitted. So the first you click the button, the page is submitted and the error lable becomes visible. However, if checking the check box does not cause any postback, then sever does not know it is time to hide the label.
Double-click your Check Box control will generate an event handler for you, then you can add this block of code in it:

if (CheckBox1.Checked)
{
   ErrorLabel.Visible = false;
}

Open in new window

0
 
sunithnairCommented:
Try like this
if (chkAgreeToTerms.Checked == false)
        {
             
            lblcheckterms.Text = "Check agreement to continue";
            lblcheckterms.Visible = true;
            return;
        }
 
AND
 
    protected void Page_Load(object sender, EventArgs e)
    {
            lblcheckterms.Visible = false;
    }

Open in new window

0
 
1jawsAuthor Commented:
worked either way guys, how about the for the textbox same thing sunith?
0
 
1jawsAuthor Commented:
thanks guys it works
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now