Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Eddie Foreman 215 posts 288 karma points
    Mar 08, 2011 @ 13:48
    Eddie Foreman
    0

    Check if a member exists by id

    Hi Guys,

    As part of a registration process a member can either verify their email address or delete the account if they do not wish to continue. This is done via a query string from an email, where I grab the member id on page load.  To help with this I'm using

            ...
    public bool memberExists(int memId){
    Member m = new Member(memId);
    if (m != null)
    {
    return true;
    }
    else {
    return false;
    }
    }
    ...

    So far I can verify or delete an account if the member exists.  What I want to do is to display a 'the account has already been deleted' message in the usercontrol if the acount does not exist (I.e. already been deleted)  when the above returns false.  This is message is set up in the control.  But if I pass an ID in the query string (say 1702)  that does not exist.  The server error  'No node exists with '1702' is displayed.

    Not sure how to catch the server error and display the the account has already been deleted' message.  Would be grateful, if someone could point me in the right direction.

    Thanks,

    Eddie

     

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Mar 08, 2011 @ 13:56
    Hendy Racher
    0

    Hi Eddie,

    You could wrap the code with a try / catch to supress the exception:

    ...
    public bool memberExists(int memId)
    {

    try
    {

     Member m = new Member(memId); // Exception thrown if memId doesn't exist
    return true;
    }
    catch
    {
    return false;
    }
    }
    ...

    HTH,

    Hendy

  • Eddie Foreman 215 posts 288 karma points
    Mar 08, 2011 @ 14:28
    Eddie Foreman
    0

    Hi Hendy,

    Of course, thanks worked a treat.

    Eddie

Please Sign in or register to post replies

Write your reply to:

Draft