OHHIITSSEAN
asked on
asp.net client side validation by calling page method
Dear asp.net gurus:
I have a asp.net web page where I need user enter product serial number, and I need to validate the user's entry; if the serial number already exists in SQL server database, then asp.net validator will display error message like 'serial number has been used'. I do not want to do this check on the clientvalidation. I knew that can be done by creating a javascript calling a asp.net static page method and then return the isvalid value to validator. The isvalid value is exchange by using JSON serialization?
I just wonder if anybody can give me some example and source code to show me how to implement the way I want it to be.
Please do not just copy and paste some links to me, please give me some explananation and then I can know how to integrate with my project.
Thanks in advance.
Shawn
I have a asp.net web page where I need user enter product serial number, and I need to validate the user's entry; if the serial number already exists in SQL server database, then asp.net validator will display error message like 'serial number has been used'. I do not want to do this check on the clientvalidation. I knew that can be done by creating a javascript calling a asp.net static page method and then return the isvalid value to validator. The isvalid value is exchange by using JSON serialization?
I just wonder if anybody can give me some example and source code to show me how to implement the way I want it to be.
Please do not just copy and paste some links to me, please give me some explananation and then I can know how to integrate with my project.
Thanks in advance.
Shawn
ASKER
Hello saritapate:
Thanks for your prompt response.
Like I said, I need to check if the serial number exists in the serial number registration table of SQL server, your workaround is not the implementation I want. I need a something like asp:customvalidator onclientvalidation calling a javascript whose function can call asp.net static page method, the page method can communication with SQL server, checking if the record already exists or not, then sending the ture/false value to javascript and then javascript can determine if isvalid is true or false and notify customvalidator.
Thanks for your time and support.
Sean
Thanks for your prompt response.
Like I said, I need to check if the serial number exists in the serial number registration table of SQL server, your workaround is not the implementation I want. I need a something like asp:customvalidator onclientvalidation calling a javascript whose function can call asp.net static page method, the page method can communication with SQL server, checking if the record already exists or not, then sending the ture/false value to javascript and then javascript can determine if isvalid is true or false and notify customvalidator.
Thanks for your time and support.
Sean
ASKER
Hello ASP.Net gurus:
Anyone have ideas?
Anyone have ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks ddayx10.
YW :)
--------------------------
using System.Text.RegularExpress
#region securitycodebysarita
int Invalidtext;
Regex rx = new Regex("[^a-zA-Z0-9:$@.!_/\
private void Txt_Validation(Control ControlContainer)
{
try
{
foreach (Control Ctl in ControlContainer.Controls)
{
if ((Ctl.Controls != null))
{
Txt_Validation(Ctl);
if (Ctl is System.Web.UI.WebControls.
{
try
{
TextBox tx = new TextBox();
tx = (TextBox)Ctl;
if ((rx.IsMatch(tx.Text)))
{
Invalidtext = Invalidtext + 1;
string StrScript = "";
StrScript = "<script type='text/javascript'>ale
System.Web.UI.ScriptManage
return;
}
}
catch (Exception ex)
{
}
}
}
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
******************put this code before any save or update.this will validate all your textbox ******************
Invalidtext = 0;
Txt_Validation(this);
if (Invalidtext > 0)
{
Invalidtext = 0;
return;
}
Note : Change new Regex("[^a-zA-Z0-9:$@.!_/\