I am trying to hide the whole div programmatically, using the following code:
System.Web.UI.Control divMask = (System.Web.UI.Control)this.Page.FindControl("urinaDiv");
System.Web.UI.HtmlControls.HtmlGenericControl htmlCtrl = (System.Web.UI.HtmlControls.HtmlGenericControl)divMask;
htmlCtrl.Attributes["Visible"] = "false";
And here is the div:
<div id="urinaDiv" sytle="width: 600px" runat="server">
<asp:Label ID="relatorioUrinaLabel" runat="server" Text="Relatórios Urina"></asp:Label>
<br />
<br />
<asp:GridView ID="urinasGridview" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource3">
<Columns>
<asp:BoundField DataField="idUtente" HeaderText="IDUten" SortExpression="idUtente" />
<asp:BoundField DataField="nome" HeaderText="Nome" SortExpression="nome" />
<asp:BoundField DataField="apelido" HeaderText="Apelido" SortExpression="apelido" />
<asp:BoundField DataField="data" HeaderText="Data" SortExpression="data" />
<asp:BoundField DataField="idUtenteMarcacao" HeaderText="idUtenteMarcacao" SortExpression="idUtenteMarcacao" visible="false"/>
<asp:BoundField DataField="densidade" HeaderText="Densidade" SortExpression="densidade" />
<asp:BoundField DataField="ph" HeaderText="pH" SortExpression="ph" />
<asp:BoundField DataField="glicose" HeaderText="Glicose" SortExpression="glicose" />
<asp:BoundField DataField="proteinas" HeaderText="Proteínas" SortExpression="proteinas" />
<asp:BoundField DataField="limitacoes" HeaderText="Limitcações" SortExpression="limitacoes" />
<asp:BoundField DataField="observacoes" HeaderText="Obs." SortExpression="observacoes" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource3" runat="server" SelectMethod="getRelatoriosUrina"
TypeName="BusinessLogicLayer.Lab_Manager" ></asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource6" runat="server" SelectMethod="getRelatoriosUrinaUtente"
TypeName="BusinessLogicLayer.Lab_Manager" OnSelecting="urinaSelecting" ><SelectParameters>
<asp:Parameter Name="idUtente" /></SelectParameters></asp:ObjectDataSource>
<br />
<br />
</div>
But I get the following error:
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
Thanks alot in advance!!
There is no need to do all that casting when you have runat="server"
Use just Visible property:
urinaDiv.Visible=false;