ASP .NET Displaying Error Messages



  • I've got a few pages that I am working on that are long enough to require vertical scrolling in resolutions above 1024 X 760.  That's fine, excpet when I want to display an error message to the user.  Typically, I just have an Label named ErrorMessage at the bottom of the page that only shows up when an error occurs.  The thing is, on these long pages, the user won't see the ErrorMessage Label unless they scroll down, which kind of sucks.  How do you all display error messages on the pages you write?

    Note:  I've had a cold and been on Nyquil most of this week, so if this is a stupid question or I'm barely coherent, please accept my apologi...zzzzzzzzz.



  • Simple, put the error label at the top :)



  • [quote user="growse"]Simple, put the error label at the top :)
    [/quote]

     

    That'd be fine, but then I have the same problem whenever an error occurs when the user is at the bottom of the page.  By the way, I'm using ASP.NET 2.0's MaintainScrollPosition setting so that whenever the page is posted back, the user doesn't lose their position on the page.  Thus, it they're in the middle of the page and can't see the top or the bottom, then when they click a button that DoesSomething, and DoesSomething fails, they won't see any error messages that I stick at the top or bottom of the page.



  • How about set the css of the label to be a position: fixed. Then it will show up in the same place on the display regardless of where the user is scrolled to on the page. Could probably even include a close button which, with some javascript, sets the display attribute of the label to 'none', hiding it.

    http://www.cssplay.co.uk/layouts/fixed.html 



  • [quote user="UncleMidriff"]

    [quote user="growse"]Simple, put the error label at the top :)
    [/quote]

     

    That'd be fine, but then I have the same problem whenever an error occurs when the user is at the bottom of the page.  By the way, I'm using ASP.NET 2.0's MaintainScrollPosition setting so that whenever the page is posted back, the user doesn't lose their position on the page.  Thus, it they're in the middle of the page and can't see the top or the bottom, then when they click a button that DoesSomething, and DoesSomething fails, they won't see any error messages that I stick at the top or bottom of the page.

    [/quote]

    Are you using the regular validation controls for ASP.NET?  If you're not trying to avoid using javascript on your pages, you can have message box pop up with the error messages if that works for you.  Just set ShowMessageBox="True" on the validation summary control.  Or, if you are not using the validation controls (which you should if you can, they save lots of coding and work great both server and client-side) you can use that same basic concept but code it manually.  If a messageBox is not too intrusive for your app.  (They can be annoying!)





     



  • [quote user="Jeff S"][quote user="UncleMidriff"]

    [quote user="growse"]Simple, put the error label at the top :)
    [/quote]

     

    That'd be fine, but then I have the same problem whenever an error occurs when the user is at the bottom of the page.  By the way, I'm using ASP.NET 2.0's MaintainScrollPosition setting so that whenever the page is posted back, the user doesn't lose their position on the page.  Thus, it they're in the middle of the page and can't see the top or the bottom, then when they click a button that DoesSomething, and DoesSomething fails, they won't see any error messages that I stick at the top or bottom of the page.

    [/quote]

    Are you using the regular validation controls for ASP.NET?  If you're not trying to avoid using javascript on your pages, you can have message box pop up with the error messages if that works for you.  Just set ShowMessageBox="True" on the validation summary control.  Or, if you are not using the validation controls (which you should if you can, they save lots of coding and work great both server and client-side) you can use that same basic concept but code it manually.  If a messageBox is not too intrusive for your app.  (They can be annoying!)[/quote]

     

    I've thought about using validation controls, but how could they be used to handle errors that aren't really associated with another control on the page?

    For instance, say I have an Update Foo page where a user can edit information about a particular Foo and then click a Save button to commit the changes to the database.  Now, say that the database server just exploded or some third party component or web service decided to gag on the information...whatever the reason, an exception is thrown, and I need to let the user know that something went wrong.  Would you use validation controls for that kind of thing, and if so, could you explain to me how you would go about doing that?



  • [quote user="UncleMidriff"][quote user="Jeff S"][quote user="UncleMidriff"]

    [quote user="growse"]Simple, put the error label at the top :)
    [/quote]

     

    That'd be fine, but then I have the same problem whenever an error occurs when the user is at the bottom of the page.  By the way, I'm using ASP.NET 2.0's MaintainScrollPosition setting so that whenever the page is posted back, the user doesn't lose their position on the page.  Thus, it they're in the middle of the page and can't see the top or the bottom, then when they click a button that DoesSomething, and DoesSomething fails, they won't see any error messages that I stick at the top or bottom of the page.

    [/quote]

    Are you using the regular validation controls for ASP.NET?  If you're not trying to avoid using javascript on your pages, you can have message box pop up with the error messages if that works for you.  Just set ShowMessageBox="True" on the validation summary control.  Or, if you are not using the validation controls (which you should if you can, they save lots of coding and work great both server and client-side) you can use that same basic concept but code it manually.  If a messageBox is not too intrusive for your app.  (They can be annoying!)[/quote]

     

    I've thought about using validation controls, but how could they be used to handle errors that aren't really associated with another control on the page?

    For instance, say I have an Update Foo page where a user can edit information about a particular Foo and then click a Save button to commit the changes to the database.  Now, say that the database server just exploded or some third party component or web service decided to gag on the information...whatever the reason, an exception is thrown, and I need to let the user know that something went wrong.  Would you use validation controls for that kind of thing, and if so, could you explain to me how you would go about doing that?

    [/quote]

    Gotcha, I wasn't sure what kind of validation you were doing -- input validation or  handling server-side errors.  You definitely would not use the validation controls for ASP.NET then in your situation.

    It is hard to give you the best answer without knowing how your page is coded up, but I'd say that scrolling the page to the top to show an error like this should be fine -- it's not a data input error, after all.  Or even re-directing to a more specific error page.  Or a pop-up window or message box.  It's hard to guess what would work best without more info.

     



  • I'd rather not redirect, but if that were the only way, I guess I'd try it.

    What I've ended up doing is setting MaintainScrollPosition to false whenever there is a server-side error.  This way the user gets thrown back to the top of the page, where my error message is displayed.  They can click an OK button in the error message div that will make it go away and set MaintainScrollPosition back to True.  That seems WTF-y to me though.  Is there some easy way to throw the user to the top (or bottom) of the page that I'm missing?



  • [quote user="UncleMidriff"]

    I'd rather not redirect, but if that were the only way, I guess I'd try it.

    What I've ended up doing is setting MaintainScrollPosition to false whenever there is a server-side error.  This way the user gets thrown back to the top of the page, where my error message is displayed.  They can click an OK button in the error message div that will make it go away and set MaintainScrollPosition back to True.  That seems WTF-y to me though.  Is there some easy way to throw the user to the top (or bottom) of the page that I'm missing?

    [/quote]

    Something like this maybe?

    <script type="text/javascript">
    function scrolltop() {
        document.location = "#top"
    }
    </script>
    <body onload="scrolltop">
    <a name="top"> 
    

    I recall there's some simple way to dynamically register an onload script via ASP.NET, though I don't remember the exact syntax. And I don't know for sure if document.location is what you set to jump to a named anchor within a page. The idea would still be the same, though.



  • Sorry for not responding sooner...


    Thanks for the tip. I'll have to give it a try.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.