Referencing nested div in FormView


I am trying to dynamically hide a Div within a FormView control.  The problem though is that the code behind can't "see" it and so far I haven't found a way to get around it.  When the Div isn't nested, then it's no problem.  Unfortunately I can't avoid nesting it.

I've run into similar issues with other controls, but have been able to get to the control by way of FormView.FindControl and CType-ing it to the control type.  However, for the Div, I can't seem to find anything that CType accepts.  Other semi-related solutions suggested HTMLGenericControl, but that didn't work.  In fact one of the other solutions suggested to the poster to use something else for his issue than HTMLGenericControl because he could never get it to work either.  (That solution was to something that doesn't apply here btw).

Any ideas?  If there is another way to dynamically hide the Div, that would be good too.  The code behind will know "when", I just need to be able to tell the page!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom KnowltonWeb developerCommented:
div tags do have a Visible property.
pfcs_sql_adminAuthor Commented:
Yes they do ... IF you can see them from the code-behind.  That's my problem.  If they are nested within the formview, they can't be "seen."

And trying to expose them via CType to a HTMLGenericControl doesn't work.  (Even nested, this works fine if it's a textbox, dropdownlist or anything else like that.  As a Div, there doesn't appear to be anything that exposes it).
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tom KnowltonWeb developerCommented:
These divs have ID's assigned to them ... and you still can't see them in the code-behind?
Tom KnowltonWeb developerCommented:
Can you provide sample code?
pfcs_sql_adminAuthor Commented:
I've attached some brevity-edited snippets.

The FormView and a couple of the Divs are shown.  The divAdmin one is the one I want to dynamically hide based on some other inputs.  It is also the div I can't see from the code-behind.

As a point of reference, the divHiddens at the bottom can be seen without any problem.  But the difference is that it isn't nested within the FormView.  The dims I included are there to demonstrate the things I had to do in order to get to the textboxes within the nests.  But I can't seem to find a way to address the div itself by this type of method.

    <asp:FormView ID="fmvEdit" runat="server" DataSourceID="srcFormDetail" AllowPaging="false" DefaultMode="Edit" Width="1024px">
    <div id="PrettyFrame" style=".....">
        <div id="divUser" style="background-color:#E0D5C5">
		.... chopped
        <div id="divAdmin" style="background-color:#E0D5C5" runat="server">
		... chopped
    <div id="divHiddens" runat="server">
        <asp:TextBox ID="txtIsAdmin" runat="server"  Visible="true"></asp:TextBox>
        <asp:Textbox ID="txtIsPhysfac" runat="server" Visible="true"></asp:Textbox>
        <asp:TextBox ID="txtUserName" runat="server" Visible="true"></asp:TextBox>
        <asp:TextBox ID="txtFileID" runat="server" Visible="true"></asp:TextBox>
Dim strOwner As String = Server.HtmlDecode(CType(fmvEdit.FindControl("txtowner"), System.Web.UI.WebControls.TextBox).Text)
Dim strAdminComment As String = Server.HtmlDecode(CType(fmvEdit.FindControl("txtAdminComment"), System.Web.UI.WebControls.TextBox).Text)

Open in new window

Tom KnowltonWeb developerCommented:
In your code-behind, can you reference   divHiddens   ?
pfcs_sql_adminAuthor Commented:
Yes.  I can reference it just fine.  It's why I included it in the example so that you could see the only difference being that one is nested and the other isn't.

Tom KnowltonWeb developerCommented:
Sorry to be so dense.  I guess I don't see what the problem is.  Nested or not the divs should be accessible via their ID.

Can you create a new website with a Default.aspx and reproduce this problem?

Then include the code behind AND markup as code snippets and I will try to make it happen as well.
pfcs_sql_adminAuthor Commented:
I don't think the issue is the nesting itself, I think it has to do with being nested within the FormView.

If you look at the two last lines of my code I included, there are two Dim statements.  With the other controls, I have to do a FindControl on the FormView and then CType it to refer to the proper control.  But ASP doesn't (seem to) recognize a Div as a control, even with an ID, so I can't find anything to CType it to.  HTMLGenericControl didn't seem to work.
pfcs_sql_adminAuthor Commented:
Oh, and you aren't being dense, because you said it straight out yourself, "Nested or not the divs should be accessible via their ID."  I agree, they SHOULD be hehe, but they don't seem to be (within a FormView anyway).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.