What can i use instead of a <div> to wrap around a <tr> as I get a warning on build. It still works as expected but I don't like warnings.
Initially I had the following
....but my find control method that dynamically handles the enable and visibility of the controls can not seem to find the DropDownList ddl_vendor. It seems to stem from the runat="server" in the <tr> element. But if I don't have runat="server" in the element then I can't show and then re-hide the row from the code behind.
FindControl method
I know there are more efficient and prettier ways to do this, but I am very new to .NET and programming in general so I was never able to get others code to work for my situation so I made my own.
Thanks in advance for you time and helpful comments.
Code:
<table>
[red]<div id="div_VENDOR" runat="server" visible="false">[/red]
<tr>
<td class="td_label_grey">
<label class="label_label">Vendor:</label>
</td>
<td>
<asp:Label CssClass="label_text" runat="server" ID="lbl_vendor"></asp:Label>
<asp:DropDownList ID="ddl_vendor" CssClass="ddl_style" runat="server"
AutoPostBack="True" onselectedindexchanged="ddl_vendor_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
</table>
Initially I had the following
Code:
<table>
[red]<tr id="tr_VENDOR" runat="server" visible="false">[/red]
<td class="td_label_grey">
<label class="label_label">Vendor:</label>
</td>
<td>
<asp:Label CssClass="label_text" runat="server" ID="lbl_vendor"></asp:Label>
<asp:DropDownList ID="ddl_vendor" CssClass="ddl_style" runat="server"
AutoPostBack="True" onselectedindexchanged="ddl_vendor_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
</table>
....but my find control method that dynamically handles the enable and visibility of the controls can not seem to find the DropDownList ddl_vendor. It seems to stem from the runat="server" in the <tr> element. But if I don't have runat="server" in the element then I can't show and then re-hide the row from the code behind.
FindControl method
Code:
foreach (Control ctlMaster in Page.Controls)
{
if (ctlMaster is MasterPage)
{
foreach (Control ctlForm in ctlMaster.Controls)
{
if (ctlForm is HtmlForm)
{
foreach (Control ctlContent in ctlForm.Controls)
{
if (ctlContent is ContentPlaceHolder)
{
foreach (Control ctlParent in ctlContent.Controls) //Find user control
{
foreach (Control ctlChild in ctlParent.Controls)
{
foreach (Control ctlGrandChild in ctlChild.Controls)
{
if (ctlGrandChild is TextBox)
{
((TextBox)ctlGrandChild).CssClass = myStyle;
((TextBox)ctlGrandChild).Enabled = p;
}
else if (ctlGrandChild is Label && ((Label)ctlGrandChild).CssClass == "label_text")
{
((Label)ctlGrandChild).Visible = !p;
}
else if ((ctlGrandChild is DropDownList))
{
((DropDownList)ctlGrandChild).Enabled = p;
((DropDownList)ctlGrandChild).Visible = p;
}
}
}
}
}
}
}
}
}
}
I know there are more efficient and prettier ways to do this, but I am very new to .NET and programming in general so I was never able to get others code to work for my situation so I made my own.
Thanks in advance for you time and helpful comments.