Custom validator doesnt show error message but shows server error

Discussion in 'ASP .Net' started by =?Utf-8?B?cG11ZA==?=, Feb 1, 2005.

  1. 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


    --
    pmud
    =?Utf-8?B?cG11ZA==?=, Feb 1, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?cG11ZA==?=

    Axel Dahmen Guest

    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" <> schrieb im Newsbeitrag
    news:...
    > 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
    >
    >
    > --
    > pmud
    Axel Dahmen, Feb 1, 2005
    #2
    1. Advertising

  3. you can try to put the code below to the event of submit.

    if (Page.IsValid)
    {
    }

    "pmud" wrote:

    > 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
    >
    >
    > --
    > pmud
    =?Utf-8?B?UGVuZyBKaWU=?=, Feb 1, 2005
    #3
  4. Re: Custom validator doesnt show error message but shows server er

    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" <> schrieb im Newsbeitrag
    > news:...
    > > 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
    > >
    > >
    > > --
    > > pmud

    >
    >
    >
    =?Utf-8?B?cG11ZA==?=, Feb 1, 2005
    #4
  5. RE: Custom validator doesnt show error message but shows server er

    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" wrote:

    > you can try to put the code below to the event of submit.
    >
    > if (Page.IsValid)
    > {
    > }
    >
    > "pmud" wrote:
    >
    > > 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
    > >
    > >
    > > --
    > > pmud
    =?Utf-8?B?cG11ZA==?=, Feb 1, 2005
    #5
  6. Re: Custom validator doesnt show error message but shows server er

    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" <> wrote in message
    news:...
    > 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" <> schrieb im Newsbeitrag
    > > news:...
    > > > 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
    > > >
    > > >
    > > > --
    > > > pmud

    > >
    > >
    > >
    William F. Robertson, Jr., Feb 1, 2005
    #6
  7. Re: Custom validator doesnt show error message but shows server er

    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, Jr." wrote:

    > 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" <> wrote in message
    > news:...
    > > 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" <> schrieb im Newsbeitrag
    > > > news:...
    > > > > 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
    > > > >
    > > > >
    > > > > --
    > > > > pmud
    > > >
    > > >
    > > >

    >
    >
    >
    =?Utf-8?B?cG11ZA==?=, Feb 3, 2005
    #7
  8. =?Utf-8?B?cG11ZA==?=

    Axel Dahmen Guest

    Re: Custom validator doesnt show error message but shows server er

    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" <> schrieb im Newsbeitrag
    news:...
    > 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, Jr." wrote:
    >
    > > 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" <> wrote in message
    > > news:...
    > > > 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" <> schrieb im Newsbeitrag
    > > > > news:...
    > > > > > 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
    > > > > >
    > > > > >
    > > > > > --
    > > > > > pmud
    > > > >
    > > > >
    > > > >

    > >
    > >
    > >
    Axel Dahmen, Feb 4, 2005
    #8
  9. Re: Custom validator doesnt show error message but shows server er

    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" wrote:

    > 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" <> schrieb im Newsbeitrag
    > news:...
    > > 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, Jr." wrote:
    > >
    > > > 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" <> wrote in message
    > > > news:...
    > > > > 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" <> schrieb im Newsbeitrag
    > > > > > news:...
    > > > > > > 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
    > > > > > >
    > > > > > >
    > > > > > > --
    > > > > > > pmud
    > > > > >
    > > > > >
    > > > > >
    > > >
    > > >
    > > >

    >
    >
    >
    =?Utf-8?B?cG11ZA==?=, Feb 11, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. z. f.
    Replies:
    2
    Views:
    465
    Thomas Dodds
    Aug 3, 2004
  2. dave
    Replies:
    2
    Views:
    407
  3. gce
    Replies:
    0
    Views:
    749
  4. Replies:
    3
    Views:
    420
    alex23
    May 27, 2008
  5. Gianni

    IE shows false and Firefox shows true

    Gianni, Jul 10, 2009, in forum: Javascript
    Replies:
    3
    Views:
    436
    Thomas 'PointedEars' Lahn
    Jul 10, 2009
Loading...

Share This Page