Link to home
Start Free TrialLog in
Avatar of pfcs_sql_admin
pfcs_sql_admin

asked on

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!
div tags do have a Visible property.
Avatar of pfcs_sql_admin
pfcs_sql_admin

ASKER

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).
These divs have ID's assigned to them ... and you still can't see them in the code-behind?
Can you provide sample code?
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

In your code-behind, can you reference   divHiddens   ?
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.

:)
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of pfcs_sql_admin
pfcs_sql_admin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial