Hello my fellow Daniwebers,

I have a question for you.

I have an asp.net page that contains a structure that looks like so:

<asp:MultiView>
    <asp:View>
        <asp:UpdatePanel>
            <asp:Panel>
                <asp:TextBox ID="txtStartDate" 
                             runat="server"
                             AutoPostBack="true" />
                <asp:TextBox ID="txtEndDate" 
                             runat="server"
                             AutoPostBack="true" />
            </asp:Panel>
        </asp:UpdatePanel>
    </asp:View>
</asp:MultiView>

The curious problem is that I can't reference the two controls.

(The code behind is vb.net)

I have used:

txtStartDate.Text

and

Dim txtStart as TextBox = FindControl("txtStartDate")
Dim txtStart as TextBox = panelName.FindControl("txtStartDate")

To no avail.

Some times they will retrieve the control, but most of the time they will return null values.

Has anyone else had this issue before?

If so, can you please shed some light on my situation?

I would greatly appreciate it!

Thank you,
Begginnerdev

have you tried

PanelID.FindControl("txtStartDate")
?
you might have to drill down from the view and/or multiview.

I have tried stepping all the way down the page's structure to no avail.

It works some times, then other times it just returns null and throws a null reference exception when I try to perform any actions with/against it.

Shouldn't the controls in the UpdatePanel be inside of a <ContentTemplate> tag?

They are, I had forgotten to add them. (Don't want to copy/paste 400 lines of asp markup)

Sorry!

I understand, just wanted to make sure. Have a look at this and see if it helps.

Thank you for the link.

I have tried this and it is still returning a null reference.

The page validates before getting searched, could this cause a null reference?

(Some what new to ASP)

are you creating any of these controls dynamically or are they all defined on the .aspx page? With the MultiView all of the controls are present on the page that are defined in the view. It should just be a matter of accessing it like any other control. TextBox1.Text or DropDownList1.SelectedValue, for example.

Sorry for my leave of absence.
I have found the solution; the controls were being disposed then recreated in code. (No clue why he did this.)
Changed the disposing to clearing all controls and it works fine!
Thank you for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.