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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:35:14+00:00 2026-06-01T07:35:14+00:00

Basically I’m Trying to put out on the Textbox inside the Shared Function, But

  • 0

Basically I’m Trying to put out on the Textbox inside the Shared Function, But i didn’t access the Textbox inside the Shared Function Then i created an object of the _Default Class to access the Textbox.
After that i access the Textbox, but during running state it give me error NullReference, when i toggle i found that Textbox1.text = Nothing instead of Textbox1.text=””
Below is the Small Code which i made for sample

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles       
    Me.Load        
        TextBox1.Text = "123"        
        TestClass()        
    End Sub       

    Protected Shared Sub TestClass()       
        Dim MyF1 As New _Default       
        MyF1.TextBox1.Text = "ABC"       
    End Sub       
  • 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-01T07:35:16+00:00Added an answer on June 1, 2026 at 7:35 am

    TextBox1 is an instance variable of your Page class, created (probably) by the ASP.NET designer.

    Thus, you cannot access it in static/shared context.

    When ASP.NET receives a request, it:

    • creates an instance of your _Default class
    • populates the controls of _Default class according to the data that comes from the client (e.g. form data)
    • does a lot of other operations which are not relevant in this context

    In your scenario, you create an instance of the _Default class, but don’t set any of its properties.

    This results in the Textbox1 property being null and that’s why it throws NullreferenceException when used.

    There are two possible solutions:

    • mark the TestClass method as instance method (drop the Shared keyword)
    • pass the current instance of _Default as a parameter to the static/shared method, like so:

      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        
          TextBox1.Text = "123"        
          TestClass(Me)        
      End Sub       
      
      Protected Shared Sub TestClass(currentPage as _Default)       
          currentPage.TextBox1.Text = "ABC"       
      End Sub 
      

    The second solution requires that the TextBox1 property should be declared as public.

    (sorry if there are any VB mistakes; I’m a C# programmer ☺)

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

Sidebar

Related Questions

Basically, I have an object that I think should be garbage-collected but it's not.
Basically, I would like a brief explanation of how I can access a SQL
Basically I am trying to restart a service from a php web page. Here
Basically, I'm trying to tap into the Soap pipeline in .NET 2.0 - I
Basically I'm trying to accomplish the same thing that mailto:bgates@microsoft.com does in Internet Explorer
Basically, what I'm trying to create is a page of div tags, each has
Basically what I'm trying to do is make a very simple vertical bullet projectile
Basically this function is meant to store the height value of the element that
basically I have a function that resizes elements accordingly with jquery triggering the function
Basically I'm trying to improve on the Ghosts in a Pacman game I'm making.

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.