• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1523
  • Last Modified:

Referencing nested div in FormView

Hello,

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!
0
pfcs_sql_admin
Asked:
pfcs_sql_admin
  • 5
  • 5
1 Solution
 
Tom KnowltonWeb developerCommented:
div tags do have a Visible property.
0
 
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).
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Tom KnowltonWeb developerCommented:
These divs have ID's assigned to them ... and you still can't see them in the code-behind?
0
 
Tom KnowltonWeb developerCommented:
Can you provide sample code?
0
 
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">
    <EditItemTemplate>
    <div id="PrettyFrame" style=".....">
        <div id="divUser" style="background-color:#E0D5C5">
 
		.... chopped
 
        </div>
        <div id="divAdmin" style="background-color:#E0D5C5" runat="server">
 
		... chopped
 
        </div>
    </div>
    </EditItemTemplate>
 
    </asp:FormView>
 
 
    <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>
    </div>
 
 
-------------
 
 
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

0
 
Tom KnowltonWeb developerCommented:
In your code-behind, can you reference   divHiddens   ?
0
 
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.

:)
0
 
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.
0
 
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.
0
 
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).
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now