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 9028645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:02:25+00:00 2026-06-16T07:02:25+00:00

I’m moving from PHP to ASP.NET/C#. So far so good, but I don’t understand

  • 0

I’m moving from PHP to ASP.NET/C#. So far so good, but I don’t understand how to instantiate a class within a ASP.NET C# class page.

For example I have login.aspx:

<%@ Page Language="C#" Inherits="Portal.LoginService" src="LoginService.cs" %>

<!DOCTYPE html>
<body>
    <form runat="server" id="login" name="login">           
        <p>Username:</p><input type="text" id="username" name="username" runat="server" />  

        <p>Password:</p><input type="password" id="password" name="password" runat="server" />

        <input type="submit" name="submit" OnServerClick="Post_Form" runat="Server" /> 
    </form>
</body>

LoginService.cs:

using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
namespace Portal {
public class LoginService : Page {

    protected HtmlInputControl username, password;

    public void Post_Form(object sender, EventArgs e) {

        if (username.Value != "" && password.Value != "") {
            //LOGIC HERE

            //This doesn't work
            CustomSanitize a = new CustomSanitize();                              
        }
    }
}
}

CustomSanitize.cs:

using System;
namespace Portal {
    public class CustomSanitize {

        //instantiate here

        public string sanitizeUserPass() {
                return "logic here"
            }
    }
}

In other words, I want to use methods from different classes with the classes I have setup with ASP.NET C#. Namespaces didn’t work for me thus far.

Thank you for any input.

  • 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-06-16T07:02:26+00:00Added an answer on June 16, 2026 at 7:02 am

    If I undertstood you correctly, wrap CustomSanitize in a namespace i.e:

    namespace MyProject {
        public class CustomSanitize {
    
            //instantiate here
    
            public string sanitizeUserPass() {
                    return "logic here"
                }
        }
    }
    

    Then wrap LoginService.cs in the same namespace. i.e

    namespace MyProject {
        public class LoginService : Page {
    
            protected HtmlInputControl username, password;
    
            public void Post_Form(object sender, EventArgs e) {
    
                if (username.Value != "" && password.Value != "") {
                    //LOGIC HERE
    
                    //This doesn't work
                    //CustomSanitize a = new CustomSanitize();                              
                }
            }
        }
    }
    

    You should now have access to CustomSanitize a = new CustomSanitize();

    You can also create more namespaces to split up your project. i.e namespace MyProject.Helper to wrap all your helper functions, then just add using MyProject.Helper to the top of the .cs file you wish to use the classes on.

    Edit:

    Please note, when adding a namespace to your project / wrapping classes in a namespace you need to reference them via that namespace via using or directly like MyProject.LoginService. This must be done on aspx, ascx pages as well using the @ Page declaration.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.