Custom validator doesnt show error message but shows server error

G

Guest

Hi,

I am using a compare validator in asp.net application(c# code). This Custom
validator is used for comparing a value enterd by the user against the
primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS IN
THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED.

For this, I used the reference artiicle
"http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vbcon/html/vbtskvalidatingagainstvaluesindatabase.asp" .

But it doesnt work i.e, when i enter a value(which already exists in the
database) in the text box & hit submit, the Validation summary DOESNT SHOW
ERROR MESSAGE.
Instead, I get the error as::

Server Error in '/NEW' Application.

Violation of PRIMARY KEY constraint 'PK_FormFields'. Cannot insert duplicate
key in object 'FormFields'. The statement has been terminated.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

RATHER THAN THE USER BEING SHOWN THIS Server error page, I want the CUSTOM
VALIDATOR TO CHECK IF THE VALUE ALREADY EXISTS IN THE DATABASE,then THE
VALIDATION SUMMARY SHOULD SHOW ERROR.


My code is::

private void CustomValidator2_ServerValidate(object
source,System.Web.UI.WebControls.ServerValidateEventArgs args)
{
DataView dv= new DataView();
dv=dsValidate1.Tables[0].DefaultView;
string asi;
args.IsValid=true;
foreach(DataRowView datarow in dv)
{
// Extract asi from the current row
asi = datarow["Alias"].ToString();

// Compare asi against user's entry
if (asi == args.Value)
{
args.IsValid = false;
}
}
}

Any help is appreciated.

Thanks
 
A

Axel Dahmen

Obviously your validator never executes "args.IsValid = false;". I'd suggest
to set a breakpoint into the validator function to see why the comparison
never reaches the if-body.

Did you call Validate() at the beginning of your Page_Load() event?

HTH,
Axel Dahmen
 
G

Guest

Hi Axel,

I just now added the Validate() function at the beginning of the page load().

Also, I inserted a breakpoint at the beginning of the custom validator's
event handler. But when I try to "Step Into" the code through the Debug tab,
the Step Into ,Step Over, StepOut or QuickWatch are all disabled. I think
the debugger is not properly installed or something. what do you think?

Is there any way to sove my problem of custom validator?

Thanks
Obviously your validator never executes "args.IsValid = false;". I'd suggest
to set a breakpoint into the validator function to see why the comparison
never reaches the if-body.

Did you call Validate() at the beginning of your Page_Load() event?

HTH,
Axel Dahmen

--
www.sportbootcharter.com

-------------------
pmud said:
Hi,

I am using a compare validator in asp.net application(c# code). This Custom
validator is used for comparing a value enterd by the user against the
primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS IN
THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED.

For this, I used the reference artiicle
"http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vbcon/html/vbtskvalidatingagainstvaluesindatabase.asp" .

But it doesnt work i.e, when i enter a value(which already exists in the
database) in the text box & hit submit, the Validation summary DOESNT SHOW
ERROR MESSAGE.
Instead, I get the error as::

Server Error in '/NEW' Application.

Violation of PRIMARY KEY constraint 'PK_FormFields'. Cannot insert duplicate
key in object 'FormFields'. The statement has been terminated.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

RATHER THAN THE USER BEING SHOWN THIS Server error page, I want the CUSTOM
VALIDATOR TO CHECK IF THE VALUE ALREADY EXISTS IN THE DATABASE,then THE
VALIDATION SUMMARY SHOULD SHOW ERROR.


My code is::

private void CustomValidator2_ServerValidate(object
source,System.Web.UI.WebControls.ServerValidateEventArgs args)
{
DataView dv= new DataView();
dv=dsValidate1.Tables[0].DefaultView;
string asi;
args.IsValid=true;
foreach(DataRowView datarow in dv)
{
// Extract asi from the current row
asi = datarow["Alias"].ToString();

// Compare asi against user's entry
if (asi == args.Value)
{
args.IsValid = false;
}
}
}

Any help is appreciated.

Thanks
 
G

Guest

Hi Peng,

I tried if (Page.IsValid){} too. But it works as long as the user doesnt
enter a duplicate value. But when page is not valid, again the server error
is shown & nothing else.

I dont understand why the custom validator is not showing error message?



Peng Jie said:
you can try to put the code below to the event of submit.

if (Page.IsValid)
{
}

pmud said:
Hi,

I am using a compare validator in asp.net application(c# code). This Custom
validator is used for comparing a value enterd by the user against the
primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS IN
THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED.

For this, I used the reference artiicle
"http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vbcon/html/vbtskvalidatingagainstvaluesindatabase.asp" .

But it doesnt work i.e, when i enter a value(which already exists in the
database) in the text box & hit submit, the Validation summary DOESNT SHOW
ERROR MESSAGE.
Instead, I get the error as::

Server Error in '/NEW' Application.

Violation of PRIMARY KEY constraint 'PK_FormFields'. Cannot insert duplicate
key in object 'FormFields'. The statement has been terminated.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

RATHER THAN THE USER BEING SHOWN THIS Server error page, I want the CUSTOM
VALIDATOR TO CHECK IF THE VALUE ALREADY EXISTS IN THE DATABASE,then THE
VALIDATION SUMMARY SHOULD SHOW ERROR.


My code is::

private void CustomValidator2_ServerValidate(object
source,System.Web.UI.WebControls.ServerValidateEventArgs args)
{
DataView dv= new DataView();
dv=dsValidate1.Tables[0].DefaultView;
string asi;
args.IsValid=true;
foreach(DataRowView datarow in dv)
{
// Extract asi from the current row
asi = datarow["Alias"].ToString();

// Compare asi against user's entry
if (asi == args.Value)
{
args.IsValid = false;
}
}
}

Any help is appreciated.

Thanks
 
W

William F. Robertson, Jr.

Are you compiling in debug mode or release mode?

It should be debug mode, and if you are trying to debug remotely on another
server, you must have installed remote debugging components.

bill

pmud said:
Hi Axel,

I just now added the Validate() function at the beginning of the page load().

Also, I inserted a breakpoint at the beginning of the custom validator's
event handler. But when I try to "Step Into" the code through the Debug tab,
the Step Into ,Step Over, StepOut or QuickWatch are all disabled. I think
the debugger is not properly installed or something. what do you think?

Is there any way to sove my problem of custom validator?

Thanks
Obviously your validator never executes "args.IsValid = false;". I'd suggest
to set a breakpoint into the validator function to see why the comparison
never reaches the if-body.

Did you call Validate() at the beginning of your Page_Load() event?

HTH,
Axel Dahmen

--
www.sportbootcharter.com

-------------------
pmud said:
Hi,

I am using a compare validator in asp.net application(c# code). This Custom
validator is used for comparing a value enterd by the user against the
primary key in the SQL database. IF the VALUE ENTERED BY THE USER
EXISTS
IN
THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE DISPLAYED.

For this, I used the reference artiicle
"http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vbcon/html/vbtskvalidatingagainstvaluesindatabase.asp" .

But it doesnt work i.e, when i enter a value(which already exists in the
database) in the text box & hit submit, the Validation summary DOESNT SHOW
ERROR MESSAGE.
Instead, I get the error as::

Server Error in '/NEW' Application.

Violation of PRIMARY KEY constraint 'PK_FormFields'. Cannot insert duplicate
key in object 'FormFields'. The statement has been terminated.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more
information
about
the error and where it originated in the code.

RATHER THAN THE USER BEING SHOWN THIS Server error page, I want the CUSTOM
VALIDATOR TO CHECK IF THE VALUE ALREADY EXISTS IN THE DATABASE,then THE
VALIDATION SUMMARY SHOULD SHOW ERROR.


My code is::

private void CustomValidator2_ServerValidate(object
source,System.Web.UI.WebControls.ServerValidateEventArgs args)
{
DataView dv= new DataView();
dv=dsValidate1.Tables[0].DefaultView;
string asi;
args.IsValid=true;
foreach(DataRowView datarow in dv)
{
// Extract asi from the current row
asi = datarow["Alias"].ToString();

// Compare asi against user's entry
if (asi == args.Value)
{
args.IsValid = false;
}
}
}

Any help is appreciated.

Thanks
 
G

Guest

Hi,

I am not able to compile in the debug mode. I tried to ude the article
http://samples.gotdotnet.com/quickstart/aspplus/doc/debugcomsdk.aspx for
this. Buw when I tried to run DbgClr.exe , i got an error as:: "Windows
cannot find the file DbgClr.exe..."

In case this is useful, VS.Net is installed on the server & I am using my
local machine for creating the applications. I am a part of the
administrators group too.

I remember, when installing VS.Net, I got some error for debugging
components & it said these components are not installed because of some
reason. What should I do? I dont want to uninstall & then reinstall .Net
again. I have already created an application using it. That application might
get affected, if I do it again?

Is there no other way of finding out why the custom validator is not showing
error when a duplicate value (which already exists in Db) is entered in the
text box?

what is the best thing to do. Please suggest.



William F. Robertson said:
Are you compiling in debug mode or release mode?

It should be debug mode, and if you are trying to debug remotely on another
server, you must have installed remote debugging components.

bill

pmud said:
Hi Axel,

I just now added the Validate() function at the beginning of the page load().

Also, I inserted a breakpoint at the beginning of the custom validator's
event handler. But when I try to "Step Into" the code through the Debug tab,
the Step Into ,Step Over, StepOut or QuickWatch are all disabled. I think
the debugger is not properly installed or something. what do you think?

Is there any way to sove my problem of custom validator?

Thanks
Obviously your validator never executes "args.IsValid = false;". I'd suggest
to set a breakpoint into the validator function to see why the comparison
never reaches the if-body.

Did you call Validate() at the beginning of your Page_Load() event?

HTH,
Axel Dahmen

--
www.sportbootcharter.com

-------------------
Hi,

I am using a compare validator in asp.net application(c# code). This
Custom
validator is used for comparing a value enterd by the user against the
primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS
IN
THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE
DISPLAYED.

For this, I used the reference artiicle
"http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vbcon/html/vbtskvalidatingagainstvaluesindatabase.asp" .

But it doesnt work i.e, when i enter a value(which already exists in the
database) in the text box & hit submit, the Validation summary DOESNT
SHOW
ERROR MESSAGE.
Instead, I get the error as::

Server Error in '/NEW' Application.

Violation of PRIMARY KEY constraint 'PK_FormFields'. Cannot insert
duplicate
key in object 'FormFields'. The statement has been terminated.

Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about
the error and where it originated in the code.

RATHER THAN THE USER BEING SHOWN THIS Server error page, I want the
CUSTOM
VALIDATOR TO CHECK IF THE VALUE ALREADY EXISTS IN THE DATABASE,then THE
VALIDATION SUMMARY SHOULD SHOW ERROR.


My code is::

private void CustomValidator2_ServerValidate(object
source,System.Web.UI.WebControls.ServerValidateEventArgs args)
{
DataView dv= new DataView();
dv=dsValidate1.Tables[0].DefaultView;
string asi;
args.IsValid=true;
foreach(DataRowView datarow in dv)
{
// Extract asi from the current row
asi = datarow["Alias"].ToString();

// Compare asi against user's entry
if (asi == args.Value)
{
args.IsValid = false;
}
}
}

Any help is appreciated.

Thanks
 
A

Axel Dahmen

Well, I can assure you, nothing harmful will happen if you'll re-install VS.
I've done it approx. 300 times in the last couple of years because of a
defective VIA chip on my K7M mainboard (by design *sigh*) which kills my
hard-disk data every now and then, and the only thing I always have to redo
is the Options settings and some other personal adjustments.

On the other hand you could do what I do whenever I can't debug: Inject
trace information code in each line from the beginning of the event down to
the line you want to reach. You can use ASP.NET's tracing functionality.
This way you can find the erroneous line more or less easily - if you really
prefer to go through the pain of re-compiling after every change instead of
re-installing VS only once...

HTH,
Axel Dahmen

------------------------------
pmud said:
Hi,

I am not able to compile in the debug mode. I tried to ude the article
http://samples.gotdotnet.com/quickstart/aspplus/doc/debugcomsdk.aspx for
this. Buw when I tried to run DbgClr.exe , i got an error as:: "Windows
cannot find the file DbgClr.exe..."

In case this is useful, VS.Net is installed on the server & I am using my
local machine for creating the applications. I am a part of the
administrators group too.

I remember, when installing VS.Net, I got some error for debugging
components & it said these components are not installed because of some
reason. What should I do? I dont want to uninstall & then reinstall .Net
again. I have already created an application using it. That application might
get affected, if I do it again?

Is there no other way of finding out why the custom validator is not showing
error when a duplicate value (which already exists in Db) is entered in the
text box?

what is the best thing to do. Please suggest.



William F. Robertson said:
Are you compiling in debug mode or release mode?

It should be debug mode, and if you are trying to debug remotely on another
server, you must have installed remote debugging components.

bill

pmud said:
Hi Axel,

I just now added the Validate() function at the beginning of the page load().

Also, I inserted a breakpoint at the beginning of the custom validator's
event handler. But when I try to "Step Into" the code through the
Debug
tab,
the Step Into ,Step Over, StepOut or QuickWatch are all disabled. I think
the debugger is not properly installed or something. what do you think?

Is there any way to sove my problem of custom validator?

Thanks

Obviously your validator never executes "args.IsValid = false;". I'd suggest
to set a breakpoint into the validator function to see why the comparison
never reaches the if-body.

Did you call Validate() at the beginning of your Page_Load() event?

HTH,
Axel Dahmen

--
www.sportbootcharter.com

-------------------
Hi,

I am using a compare validator in asp.net application(c# code). This
Custom
validator is used for comparing a value enterd by the user against the
primary key in the SQL database. IF the VALUE ENTERED BY THE USER EXISTS
IN
THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE
DISPLAYED.

For this, I used the reference artiicle
"http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vbcon/html/vbtskvalidatingagainstvaluesindatabase.asp" .

But it doesnt work i.e, when i enter a value(which already exists
in
the
database) in the text box & hit submit, the Validation summary DOESNT
SHOW
ERROR MESSAGE.
Instead, I get the error as::

Server Error in '/NEW' Application.

Violation of PRIMARY KEY constraint 'PK_FormFields'. Cannot insert
duplicate
key in object 'FormFields'. The statement has been terminated.

Description: An unhandled exception occurred during the execution
of
the
current web request. Please review the stack trace for more information
about
the error and where it originated in the code.

RATHER THAN THE USER BEING SHOWN THIS Server error page, I want the
CUSTOM
VALIDATOR TO CHECK IF THE VALUE ALREADY EXISTS IN THE
DATABASE,then
THE
VALIDATION SUMMARY SHOULD SHOW ERROR.


My code is::

private void CustomValidator2_ServerValidate(object
source,System.Web.UI.WebControls.ServerValidateEventArgs args)
{
DataView dv= new DataView();
dv=dsValidate1.Tables[0].DefaultView;
string asi;
args.IsValid=true;
foreach(DataRowView datarow in dv)
{
// Extract asi from the current row
asi = datarow["Alias"].ToString();

// Compare asi against user's entry
if (asi == args.Value)
{
args.IsValid = false;
}
}
}

Any help is appreciated.

Thanks
 
G

Guest

Hi Axel,

I did some research on Asp.net's Trace functionality. But i would need your
help with the code. I included trace= "true " in the page directive. Then
I added Trace.Write or Trace.Warn with the string message in it. But I cant
see those messages when i see the trace information through the browser.
Also, I see the trace information is overlapping my webform so i cant read
anything clearly.

My code is:
private void CustomValidator2_ServerValidate(object
source,System.Web.UI.WebControls.ServerValidateEventArgs args)
{
Trace.Write("isnside Custom validator");
DataView dv= new DataView();
dv=dsValidate1.Tables[0].DefaultView;
string asi;
args.IsValid=true;
Trace.Warn("before dataset");
foreach(DataRowView datarow in dv)
{
asi = datarow["Alias"].ToString();
Trace.Warn("dataset filled");
// Compare e-mail address against user's entry
if (asi == args.Value)
{
Trace.Warn("inside if");
args.IsValid = false;
//CustomValidator2.Visible=true;
}
else
{
args.IsValid=true;
}

}
}

What is wrong with this? Is there some better coding style for showing an
error message if the user tries to enter a value (which is a primary key of
the database) already exists in the database?




Axel Dahmen said:
Well, I can assure you, nothing harmful will happen if you'll re-install VS.
I've done it approx. 300 times in the last couple of years because of a
defective VIA chip on my K7M mainboard (by design *sigh*) which kills my
hard-disk data every now and then, and the only thing I always have to redo
is the Options settings and some other personal adjustments.

On the other hand you could do what I do whenever I can't debug: Inject
trace information code in each line from the beginning of the event down to
the line you want to reach. You can use ASP.NET's tracing functionality.
This way you can find the erroneous line more or less easily - if you really
prefer to go through the pain of re-compiling after every change instead of
re-installing VS only once...

HTH,
Axel Dahmen

------------------------------
pmud said:
Hi,

I am not able to compile in the debug mode. I tried to ude the article
http://samples.gotdotnet.com/quickstart/aspplus/doc/debugcomsdk.aspx for
this. Buw when I tried to run DbgClr.exe , i got an error as:: "Windows
cannot find the file DbgClr.exe..."

In case this is useful, VS.Net is installed on the server & I am using my
local machine for creating the applications. I am a part of the
administrators group too.

I remember, when installing VS.Net, I got some error for debugging
components & it said these components are not installed because of some
reason. What should I do? I dont want to uninstall & then reinstall .Net
again. I have already created an application using it. That application might
get affected, if I do it again?

Is there no other way of finding out why the custom validator is not showing
error when a duplicate value (which already exists in Db) is entered in the
text box?

what is the best thing to do. Please suggest.



William F. Robertson said:
Are you compiling in debug mode or release mode?

It should be debug mode, and if you are trying to debug remotely on another
server, you must have installed remote debugging components.

bill

Hi Axel,

I just now added the Validate() function at the beginning of the page
load().

Also, I inserted a breakpoint at the beginning of the custom validator's
event handler. But when I try to "Step Into" the code through the Debug
tab,
the Step Into ,Step Over, StepOut or QuickWatch are all disabled. I think
the debugger is not properly installed or something. what do you think?

Is there any way to sove my problem of custom validator?

Thanks

Obviously your validator never executes "args.IsValid = false;". I'd
suggest
to set a breakpoint into the validator function to see why the
comparison
never reaches the if-body.

Did you call Validate() at the beginning of your Page_Load() event?

HTH,
Axel Dahmen

--
www.sportbootcharter.com

-------------------
Hi,

I am using a compare validator in asp.net application(c# code). This
Custom
validator is used for comparing a value enterd by the user against the
primary key in the SQL database. IF the VALUE ENTERED BY THE USER
EXISTS
IN
THE DB , then THE ERROR MESSAGE OF THE COMPARE VALIDATOR SHOULD BE
DISPLAYED.

For this, I used the reference artiicle
"http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/vbcon/html/vbtskvalidatingagainstvaluesindatabase.asp" .

But it doesnt work i.e, when i enter a value(which already exists in
the
database) in the text box & hit submit, the Validation summary DOESNT
SHOW
ERROR MESSAGE.
Instead, I get the error as::

Server Error in '/NEW' Application.

Violation of PRIMARY KEY constraint 'PK_FormFields'. Cannot insert
duplicate
key in object 'FormFields'. The statement has been terminated.

Description: An unhandled exception occurred during the execution of
the
current web request. Please review the stack trace for more
information
about
the error and where it originated in the code.

RATHER THAN THE USER BEING SHOWN THIS Server error page, I want the
CUSTOM
VALIDATOR TO CHECK IF THE VALUE ALREADY EXISTS IN THE DATABASE,then
THE
VALIDATION SUMMARY SHOULD SHOW ERROR.


My code is::

private void CustomValidator2_ServerValidate(object
source,System.Web.UI.WebControls.ServerValidateEventArgs args)
{
DataView dv= new DataView();
dv=dsValidate1.Tables[0].DefaultView;
string asi;
args.IsValid=true;
foreach(DataRowView datarow in dv)
{
// Extract asi from the current row
asi = datarow["Alias"].ToString();

// Compare asi against user's entry
if (asi == args.Value)
{
args.IsValid = false;
}
}
}

Any help is appreciated.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top