Validating in Groups
In ASP.NET 2.0 has a new feature called Validation Groups.
If supposing you have two different sections and each of the section needs to be validated separately then Validation Groups is an interesting concept.
Each control can be tied to a specific group by using the ValidationGroup property in the controls.
Here is a simple example in ASP.NET 2.0.
Copy it to an aspx page and run it.
<form id="form1" runat="server"><div><asp:Panel ID="Panel1" runat="server"><asp:TextBox ID="TextBox1" ValidationGroup="FirstGroup" runat="server" /><asp:RequiredFieldValidator ID="RequiredFieldValidator1"ErrorMessage="First Group Validated" ValidationGroup="FirstGroup"runat="server" ControlToValidate="TextBox1" /><asp:Button ID="Button1" Text="Validate Group1"ValidationGroup="FirstGroup" runat="server" /></asp:Panel><br /><asp:Panel Height="94px" ID="Panel2" runat="server" Width="125px"><asp:TextBox ID="TextBox2" ValidationGroup="SecondGroup"runat="server" /><asp:RequiredFieldValidator ID="RequiredFieldValidator2"ErrorMessage="Second Group Validated" ValidationGroup="SecondGroup"ControlToValidate="TextBox2" runat="server" /><asp:Button ID="Button2" Text="Validate Second Group"ValidationGroup="SecondGroup" runat="server" /></asp:Panel></div></form>
Exception -al issues in .NET
Quite often I have seen "Object reference not set" error in .net applications. The error is not a developer intended error its just the basic understanding of exceptions not being clear. Whenever an exception is thrown deep in the code the developer intends to highlight this exception and hence re-throws the exception. In .net when you re-throw an exception it creates a new exception on the stack and hence this is the "Object reference not set" a very misleading error.
Therefore instead of doing this
throw new exception("Message")
do only this
throw
Hence the right exception info is obtained when the exception is handled at the interface level.
Most large projects should develop their own exception handling mechanism and not depend on this.