You must Sign In to post a response.
  • Category: .NET

    Validation in 3 tier windows application

    I want to perform validation for user input in 3 tier c# windows application.
    Where is the exact place to place the validation code (i.e. in presentation layer or BAL) and display appropriate massage related to it.

    Eg:

    if()
    {
    //errormessage..............
    }
    else
    {
    //ok......................
    }

    Please suggest solution along with sample code
  • #764914
    Hi Jayesh,

    That is up to your project, if you validate in BAL side then it's stops execute (when condition false )some functionality in Presentation side, so it would be improve the performance, but there is some drawback in that unnecessarily sometimes we will check the conditions in BAL side without need.

    Any how this is one good question, lets see our members response out of this.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #764924
    Normally we should handle the validation in the UI layer. In rare case we can handle this in the BAL.

    Handling the validation in the client side/UI side is good practice.

    By Nathan
    Direction is important than speed

  • #764929
    Hi,
    Exact place to place the validation code is UI or presentation layer because its main purpose is to translate tasks to something that user can easily understood. So do validations at UI and show user friendly messages over there.
    Hope it helps.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com

  • #764931
    Hi
    Presentation layer is best for validation. we no need go to bal part because
    our data we have in presentation so .

    2 type of valition have

    1.client side
    2.server side

    client side
    ===========

    using script like jscript and jquery we can use this

    server side
    ==============

    server side code c# code



    Client side sample

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #764932
    Hi
    try this


    Client side sample


    <script>
    function validation() {
    var txt = document.getElementById("TxtName").value;
    if (txt = '') {
    alert('Name is Empty');
    }
    return false;
    }
    </script>

    <div>
    <asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
    <asp:Button ID="BTNSUBMIT" runat="server" Text="Submit" OnClick="BTNSUBMIT_Click" />
    </div>


    Server side sample


    protected void BTNSUBMIT_Click(object sender, EventArgs e)
    {
    if (TxtName.Text == "")
    {
    //Error Message here..
    }
    }

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #764948
    if your validation are for user input then UI is the best place to validate it, use client side scripting to validate UI like javascript, if you want to validate your input with database then business layer is only good place.
    Validations can be performed on the server side or on the client side ( web browser). The user input validation take place on the Server Side during a post back session is called Server Side Validation and the user input validation take place on the Client Side (web browser) is called Client Side Validation. Client Side Validation does not require a postback. If the user request requires server resources to validate the user input, you should use Server Side Validation. If the user request does not require any server resources to validate the input , you can use Client Side Validation

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764959
    Hai Jayesh,
    The validations can be added at the client as well as the server side.
    For the client side validations, you can use the JavaScript or JQuery and for the server side, the best place to add in the BAL layer.
    So that if the server side validation fails, it will not go to the database layer and return from there. If the validations, fails, it will returns from the business logic layer to your UI.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #764978
    If the validation is related to business logic then you can write the validation logic in the business layer catch various exceptions based on the appropriate validation error and throw the error back to the presentation layer so that it is handled and displayed in the UI layer. sometimes when you write validation logic in the UI using javascript there are chances of validation being failed so make sure that you also validate in the Business Layer to avoid incorrect data being stored in the database.
    Miss. Jain
    Microsoft Certified Technology Specialist in .Net


Sign In to post your comments