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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:43:00+00:00 2026-06-09T12:43:00+00:00

I have a FormView and I need to access some Divs and other controls

  • 0

I have a FormView and I need to access some Divs and other controls that are inside it. My apsx code looks similar to this:

 <asp:FormView ID="Edit_FV" runat="server" DataKeyNames="IDproceso" DefaultMode="Edit" DataSourceID="SqlDS_Procesos">
            <EditItemTemplate>
                <div id="second_info" runat="server">
                    <div id="second_info_left" runat="server">
                        <div id="alcance" class="report_field" runat="server">
                            <p class="container-title">
                                Alcance:</p>
                            <asp:TextBox ID="TextBox14" runat="server" TextMode="multiline" Width="400px" Height="120px" Text='<%# Bind("alcance") %>' />
                        </div> 
                    </div>
                    <div id="second_info_right" runat="server">
                    <div class="valores-container" id="tipo_ahorro" runat="server">
                        <asp:CheckBox ID="ahorro_state" runat="server" Checked='<%# Bind("tipo_ahorro") %>'  />
                    </div>
                </div>
            </EditItemTemplate>
        </asp:FormView>

Now, say I want to access the CheckBox with id = ahorro_state, I tried with Edit_FV.FindControl("ahorro_state") and got a Null reference. I also tried with Edit_FV.FindControl("MainContent_Edit_FV_ahorro_state") because this is how the ID actually gets named in the final HTML document, but I got a Null reference too. The same happened when I tried accessing any of the divs (with IDs second_info,tipo_ahorro, etc..). I feel I’m doing a dumb mistake but I looked around a bit and haven’t found and answer.

Any ideas how to solve this?

EDIT: Added Code where I’m calling FindControl.

I tried both calling DataBind() from the Page_Load():

protected void Page_Load(object sender, EventArgs e)
        {

            DataBind();
            if (Edit_FV.CurrentMode == FormViewMode.Edit)
            {
                Control c = Edit_FV.FindControl("ahorro_state");//c is null here.
            }
        }

And also tried setting the OnDataBound attribute of Edit_FV: OnDataBound="onBound"

   protected void onBound(object sender, EventArgs e)
            {
                if (Edit_FV.CurrentMode == FormViewMode.Edit)
                {
                    ControlCollection a = Edit_FV.Controls;
                    Control c = Edit_FV.FindControl("ahorro_state");//c is null here
                }

            }
  • 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-09T12:43:02+00:00Added an answer on June 9, 2026 at 12:43 pm

    Although the default mode is set “Edit”, the form view won’t switch to that mode until the control is DataBound. Try calling DataBind() first, then use FindControl using the ID of your element (not the ClientID, as you tried in your second example).

    See FormView.FindControl(): object reference error for examples of where to put your FindControl logic.

    EDIT:

    There is also the possibility that your data source is not returning any data. This will result in the EditItemTemplate being empty which might explain your null reference errors. Try checking for a Edit_FV.DataItemCount > 0 before switching into Edit mode.

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

Sidebar

Related Questions

I have a formview on my aspx page containing various controls arranged using table.
I have asp:Table with number of asp:Label inside asp:FormView , it represents short stats
I'm having issues transitioning between views and need some help. This is somewhat conviluted
I have a formview, connected to an objectDataSource. It's a pretty easy code in
So I have this FormView which should only have 1 record for editing: <asp:FormView
I have a textbox in a formview that gets its data from a linqdatasource
I have a checkbox and a panel inside of a FormView control, and I
I have an asp 4.0 page using a formview and C# code as needed.
This is an odd scenario, but I have two overlapping UIViews, and I need
Okay, I have a FormView with a couple of child controls in an InsertItemTemplate.

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.