ASP.NET

Add your own error message to a ValidationSummary

There are time where you need to display a message to the users.  Here’s how to do it with a Validation Summary on your ASP.NET page. I use this when I want to display an error message that doesn’t come from an exception or another validation. This is helpful when you want all messages to have the same look and feel. Below is the code. CustomValidator val = new CustomValidator(); val.IsValid = false; val.ErrorMessage = "My error...

How to get a reference to the control that caused a post back

Here is some old code I found (in VB.NET) the will tell you what control caused the post back. ' Return a reference to the control that caused the last postback, ' even from the Page_Load event! ' It requires in input a reference to the posted-back page ' (this is necessary if you want to be able to move this function in a separate ' class ' instead of in a page's codebehind class ' ' Example: ' Private Sub Page_Load(ByVal sender As System.Object, ' ByVal e As System.EventArgs) Handles MyBase.Load ' Dim...

No back button

If your web app just can't tolerate a user clicking the back button, you can tell the browser to not cache the page. Most of the time it will listen if you use this code, which covers all the bases: Response.Expires = 60 Response.ExpiresAbsolute = DateAdd(DateInterval.Day, -1, Now()) Response.AddHeader("pragma", "no-cache") Response.AddHeader("cache-control", "private") Response.CacheControl = "no-cache"

No back button

If your web app just can't tolerate a user clicking the back button, you can tell the browser to not cache the page. Most of the time it will listen if you use this code, which covers all the bases: Response.Expires = 60 Response.ExpiresAbsolute = DateAdd(DateInterval.Day, -1, Now()) Response.AddHeader("pragma", "no-cache") Response.AddHeader("cache-control", "private") Response.CacheControl = "no-cache"