0

I want to do this type of validation using javascript on text box in asp.net on textchange event of text box below is my code in c# validtaion:

string str = "Select ReceiptNo from BranchOutwardItems where ReceiptNo='" + txtReceiptNo.Text + "'";

DataTable dt = objGlobalClass.LoadData(str);
if (dt.Rows.Count > 0)
{
     lblMsg.Text = " Receipt ID already exists.Click On ADD for Generate New Receipt ID";
}
else
{
     lblMsg.Text = "Receipt ID doesnot exists";
}
5
  • 1
    STOP using dynamic Query Commented Oct 29, 2012 at 7:09
  • You want to do a db call every time the text changes? Commented Oct 29, 2012 at 7:11
  • why not just use ajax update panel Commented Oct 29, 2012 at 7:11
  • 1
    This is not a good idea becuase: 1. javascript validation could be eliminated easily; 2. the code given is a good candidate for SQL injection. Commented Oct 29, 2012 at 7:12
  • 1
    You should use focus out. Because you are going to hit the database for each character change. Your will have to create a Web-Service or page method or http-handler which takes the value from java-script and return the appropriate message. Commented Oct 29, 2012 at 7:22

2 Answers 2

1

For this you will have to call a Page-Method or A Web-Service, Or a Http-Handler to validate the value of the text box.

Here is a similar example
Here too is a good example

Sign up to request clarification or add additional context in comments.

Comments

0
var tbl = document.getElementById('tblID');
var lbl = document.getElementById('lblID');
if(tbl != null)
{

if(tbl.rows.length > 0)
{
lbl.innerHTML = "Success Message";
}
else 
{
lbl.innerHTML = "Failed Message";

}

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.