Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3394528
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:10:51+00:00 2026-05-18T04:10:51+00:00

I have been learning C# for the past few days for use with ASP.NET

  • 0

I have been learning C# for the past few days for use with ASP.NET to create websites.

I am very new to C# but I have been thinking about how I should go about writing my code to make it as reusable as possible.

As a quick example, lets say I wanted to create a piece of code to check a users login details which I could just drop into another site at any time, and have it work with the data it gets given.

Remembering that I have no idea how I should layout my code to do this, this is the idea I came up with (I will keep it short with some kind of pseudo code):

First I create a class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Module {
    public class Login {
        public static bool check_login(string usernameCheck = "", string passwordCheck = "") {
            if(usernameCheck == "user" && passwordCheck == "password") {
                return true;
            }

            return false;
        }
    }
}

Then I would have an aspx page where the login form would go, for example:

<asp:Content ContentPlaceHolderID="column1" runat="server">
    <asp:TextBox ID="usernameInput" runat="server"></asp:TextBox>
    <asp:TextBox ID="passwordInput" runat="server"></asp:TextBox>
    <asp:Button OnClick="check_login" Text="Login" runat="server" />
</asp:Content>

And the code behind file would look like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Module {
    public partial class _default : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {

        }

        protected void check_login(object sender, EventArgs e) {
            if(Login.check_login(usernameInput.Text, passwordInput.Text)) {
                Response.Redirect("some other place");
            }
        }
    }
}

This works as expected, but what I want to know is:

  • Is there a better way to create reusable code?
  • How do you design your reusable code?

I’m sure there must be a better way for me to do this, but I just can’t think of it on my own.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:10:52+00:00Added an answer on May 18, 2026 at 4:10 am

    With regard to ASP.NET WebForms and reusability, it has to be said that the most common issue lies with putting too much logic into the code-behind files. Programmers, especially those new to ASP.NET WebForms, tend to put there parts of business logic and even database access code. After a while, it turns their application into a giant hard-to-maintain blurb.

    Extract away your business logic into a separate layer. Access it from the code-behind. Just access, not implement it directly. Stay away from the database. Only the business layer should be allowed to talk to it.

    You could even put your business logic and domain model entities into a separate class library. Then it’s how it becomes reusable.

    That’s first simple considerations before you get your hands dirty with some serious coding.

    Reusability techniques in .NET mostly revolve around shelving common code into class libraries to be used by a variety of applications.

    Reusability as applied to web applications (ASP.NET) is usually achieved with UserControls (*.ascx) for the presentation part and exposing parts of the application via web services.

    One could also mention moving the business logic into the database layer (putting it into stored procedures) but this one is commonly perceived as controversial these days.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have been learning ASP.NET (using C#) over the past few days. I have made
I have been learning ASP.NET MVC for a few months. I have learned about
I have been learning Hibernate for the past few weeks, I have gotten most
I have just started learning NHibernate. Over the past few months I have been
For the past few months I've been learning and coding successful apps and websites
I'm a newbie to ASP.NET MVC. I've been learning MVC 3 for the past
I am new to android development but in the past few weeks I have
I have been learning Ruby (Rails/Sinatra) and it's good very good but OMFG how
I have been learning iOS development for a few days now. At this moment,
I am very new to iOS Programming and have been learning for only a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.