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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:13:22+00:00 2026-06-10T22:13:22+00:00

If I have: <asp:TextBox ID=txtField1 runat=server></asp:TextBox> Then in my code-behind I can access that

  • 0

If I have:

<asp:TextBox ID="txtField1" runat="server"></asp:TextBox>

Then in my code-behind I can access that web control by its “ClientID”:

txtField1.Text = "value";

That works, but I want an alternate way to access the same web control by reference so I tried doing it this way:

TextBox myTxtField = (TextBox)Page.FindControl("txtField" + 1);
myTxtField.Text = "value";

And I am getting the error: “Object reference not set to an instance of an object.” Any idea if I am doing this right or if there is another way to reference a web control’s ID by passing in a string?

  • 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-10T22:13:23+00:00Added an answer on June 10, 2026 at 10:13 pm
    TextBox myTxtField = (TextBox)Page.FindControl("txtField" + 1);
    

    This returns null if the control is sitting on a ContentPage of a MasterPage. Then you should reference it directly (as shown below).

    I’ve written something about this issue here: https://stackoverflow.com/a/8781131/284240

    Of course it would also return null if the control has another ID or if it’s in another NamingContainer than the page(f.e. in a GridView).

    Side note:

    Then in my code-behind I can access that web control by its
    “ClientID”:

    txtField1.Text = "value";
    

    txtField1 is the ID not the ClientID and actually you’re referencing the control directly.

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

Sidebar

Related Questions

I have an asp:TextBox that looks like the following <asp:TextBox runat=server AutoPostBack=True ID=txtG1 ontextchanged=txtG1_TextChanged
I have an asp.net textbox that is disabled: <asp:TextBox ID=txtEmpName runat=server Enabled=false></asp:TextBox> Using jQuery,
i have asp text box and button control. <asp:TextBox ID=txtFName runat=server CssClass=sfInputbox></asp:TextBox> <asp:Button runat=Server
I have a asp:UpdatePanel with a asp:Button and a asp:TextBox : <asp:UpdatePanel ID=UpdatePanel1 runat=server>
I have a asp.net input box: <asp:TextBox ID=InCL runat=server Text=></asp:TextBox> As soon as a
I have asp.net code: <asp:RadioButton ID=RadioButton1 CssClass=rb1 GroupName=grp1 runat=server /> <br/> <asp:RadioButton ID=RadioButton2 CssClass=rb2
I'd like to have an asp.net textbox that people can paste content into and
In asp file I have two asp:textbox <asp:TextBox ID=textValue runat=server Width=100px/> <asp:TextBox ID=textValue2 runat=server
Suppose I have an ASP.NET Text Box as Below : <asp:TextBox ID=txtQuantity runat=server Text=0></asp:TextBox>
I have a simple asp:textbox set up like this <asp:TextBox runat=server ID=tbxWarning TextMode=MultiLine Rows=4>

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.