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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:28:18+00:00 2026-06-15T20:28:18+00:00

I have been battling this for some time and I need some guidance. I’m

  • 0

I have been battling this for some time and I need some guidance.

I’m coding in ASP.NET 4.0 WEBFORMS.

Question is: How to expose a textbox, Label or any other control to another class.

I have a webform (see below).

public partial class WebForm1 : System.Web.UI.Page
{

}

This is then referenced and sent to another class.

public class SearchInitializer
{
    private WebForm1 _webform1;

    public SearchInitializer(WebForm1 Webform1)
    {
        _webform1 = Webform1;
    }

    public void ChewSettings()
    {

        _webform1 //can't find any control in here?!
    }

}

First I thought of creating a public property which I thought I could access from the reference I sent to the new class.. But nooo!

public partial class WebForm1 : System.Web.UI.Page
{
   public string KeywordBox1 
    {
        get {return txt_keyword.Text;}
        set {txt_keyword.Text = value;}
    }

}

The I tried to inherit the Webform into the other class. Making the the property available but no luck there.

public class SearchInitializer : Webform1
{
    private WebForm1 _webform1;

    public SearchInitializer(WebForm1 Webform1)
    {
        _webform1 = Webform1;
    }

    public void ChewSettings()
    {

        _webform1 //can't find any control in here?!
    }

}

Okay an abstract class migth be of use here, inheriting everything. But I think I got that wrong to. I have events and static classes, so they can talk with the page. But I really would like not to use a static class as a container to save all the info in my controls.
So these are the examples I have tried and they all failed. So this is me basicly trying to expand what I know 😉 Thanks for reading!!
Why have they failed and how should I do it?

EDIT AS REQUESTED!

public partial class WebForm1 : System.Web.UI.Page
{

     protected void btn_click(object sender, EventArgs e)
     {
         SearchInitializer searchIni = new SearchInitializer(this);
     }

}
  • 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-15T20:28:20+00:00Added an answer on June 15, 2026 at 8:28 pm

    To expose the controls there are two methods I can think of that you can employ.

    You can remove the following statement from the myPage.designer.cs file and place it in your code behind as a public declaration:

    protected global::System.Web.UI.WebControls.TextBox myTextBox;
    

    becomes

    public System.Web.UI.WebControls.TextBox myTextBox;
    

    This should make it immediately accessible. My preferred method is to add a property for each specific control that you want to provide access to.

    public System.Web.UI.WebControls.TextBox MyTextBoxElement
    {
        get
        {
            return myTextBox;
        }
    }
    

    This allows to provide supplementary access controls if you need them or other conditionals. In any case, to access either the field or the property, the consuming object must reference this by your specific page type.

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

Sidebar

Related Questions

So I have been battling with this for some time and I need your
I have been battling with this for some time and my noob brain can't
I have a challenging problem I've been battling for some time now. The Problem:
I've been battling with this for some time and seem to be getting nowhere.
I have been battling with this for a while (even used some Ant-based workarounds),
So I have been trying and battling with this for a few hours now.
Have been working on this question for a couple hours and have come close
So I have been battling this issue for awhile now and tried many different
I've been battling with this issue for a couple of days now. I have
Hi I have been battling with this issue all day. I have a vs2010

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.