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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:39:04+00:00 2026-06-03T15:39:04+00:00

I have a field ‘x’ on the user control form which is included on

  • 0

I have a field ‘x’ on the user control form which is included on aspx page and that page using SharePoint master page. I’m trying to locate field x on aspx page in my code but it throws “Object ref not set” error. I’ve tried following but nothing works ,

((TextBox)Page.Master.FindControl("PlaceHolderMain").FindControl("Experience").FindControl("x")).Text


((TextBox)this.FindControl("x")).Text


((TextBox)Page.Master.FindControl("PlaceHolderMain").FindControl("x")).Text

I can locate the field on page source,

<input name="ctl00$PlaceHolderMain$ctl00$x" type="text" value="3" id="ctl00_PlaceHolderMain_ctl00_x" class="textbox" />

Update:-

Previously I was adding user control programmatically on load event of the aspx page,

UserControl uc = (UserControl)Page.LoadControl("Experience.ascx");
experineceForm.Controls.Add(uc);

But by seeing page source I had doubt and thought to add it in design time using following code,

<%@ Register TagPrefix="uc" TagName="Experience" Src="Experience.ascx" %>

<div id="experineceForm" runat="server">
   <uc:experience id="idExperienceForm" runat="server"/>
</div>

After doing this I’m able to find controls with following code,

((TextBox)Page.Master.FindControl("PlaceHolderMain").FindControl("idExperienceForm").FindControl("txtEmployeeComments")).Text
  • 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-03T15:39:07+00:00Added an answer on June 3, 2026 at 3:39 pm

    Try this function (below) to do a recursive search for the ID. Most probably the System.NullReferenceException: Object reference not set to an instance of an object error is because the script did not find the text box so the control did not have a .Textproperty. NB: root would be the id of an asp.net placeholder object or an asp.net panel, etc. that contains the text box you are looking for. You should test for null returns before attempting to use the control.

    public Control FindControlRecursive(Control root, string id)
    {
        if (root.ID == id) {
            return root;
        }
        Control c = default(Control);
        foreach ( c in root.Controls) {
            Control t = FindControlRecursive(c, id);
            if ((t != null)) {
                return t;
            }
        }
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a field in a CCK node form that is hidden, and has
I have some tables which all have a field named created_at , that's a
I have field in my Model which indicates whether a user wants to receive
I have a field called IntQID, which is an id for each post that
I have field X that contains text with spaces in the end of the
in my jqgrid i have field in a table which represents the id and
I have a field in a table which contains bitwise flags. Let's say for
I have an field, Address2, which is optional. Thus if it is null, no
i have field in databaase. which contains special characters. i want to escape these
In my form I have field of type entity . How to disable validation

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.