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

  • Home
  • SEARCH
  • 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 6015185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:47:59+00:00 2026-05-23T02:47:59+00:00

Basically I am not using a MasterPage and I just have a project with

  • 0

Basically I am not using a MasterPage and I just have a project with a Default.aspx with a few labels, textBoxes etc. I’ve spent several hours looking for a solution and I have found one, but something in my head still bugs me, that I didn’t do it the way I wanted to.

I have no troubles accessing them and setting their properties from the PageLoad.

But I made a class, just like the code snippet below, and it throws me an “Object reference not set to an instance of an object”. And I cannot seem to figure out what I am missing.

   class Functions 
    {
       public static void myMethod()
       {
            WebForm1 mainForm = new WebForm1();
            mainForm.myTextBox.Text = "Something.";
       }
    }

I managed to do with like this:

   class Functions 
    {
       public static void myMethod()
       {
           System.Web.UI.Page myMainForm;
           myMainForm = (System.Web.UI.Page)System.Web.HttpContext.Current.Handler;
           TextBox myTextBox = (TextBox)myMainForm.FindControl("myTextBox");
       }
    }

But it’s not about just doing it, it’s about learning where I am wrong as I cannot figure it out and I want a simpler way to do it, considering I am very new to ASP.NET. Normally when I am coding basic applications in WinForms – I don’t have problems accessing different forms.

And I don’t like doing a FindControl() for every control I am trying to access. If there is a simple and yet effective workaround I would love to hear it.

Thank you in advance.

Edit: I’ve made this example aside from my project, but it’s the idea I am trying to accomplish. There might be some small errors in the code snippets, please excuse me.

  • 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-23T02:48:00+00:00Added an answer on May 23, 2026 at 2:48 am

    Use the code-behind files for this. Don’t tightly couple business logic classes to your user interface.

    WebForm1.aspx should have WebForm1.aspx.cs if using c# or WebForm.aspx.vb if using vb, so if you have a TextBox control on WebForm1.aspx, you should be able to access it in the code-behind file (WebForm1.aspx.cs or WebForm1.aspx.vb)

    public class Validate
    {
        public bool IsEmail(string email)
        {
            //return false if invalid e-mail or true if valid
        }
    }
    

    Then in your WebForm.aspx.cs, you can call

     Validate validate = new Validate();
     bool isValidEmail = validate.IsEmail(txtEmail.Text);
    

    Where txtEmail is the control. You can make the Validate class static, so you can just do:

     bool isvalidEmail = Validate.IsEmail(txtEmail.Text);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not really sure how to title this question but basically I have an
I'm not sure if the title is very clear, but basically what I have
I have an .net C# console application (not a service). it basically connects to
I'm not a JS guy so I'm kinda stumbling around in the dark. Basically,
Basically I have some code to check a specific directory to see if an
Basically I'm going to go a bit broad here and ask a few questions
Hi Guys just wondering if you could help, I have a page in C#
Basically what I want to do it this: a pdb file contains a location
Basically, something better than this: <input type=file name=myfile size=50> First of all, the browse
Basically, I would like a brief explanation of how I can access a SQL

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.