How can I hide the HTML <tr> table row in the aspx file and include the code in the code?

I have very little search functionality and I have a table row called Search Results, I want this table row to appear whenever I have something displayed from the search results. So I want to hide this line by default and turn it on with the code behind when my search retrieves some result.

<div>
    <table>
        <tr id="srchResultHeader" style="display: none;" class="header">
            <td colspan="2" class="tdlogintitle" visible="false">Search Results</td>
        </tr>
        <tr>
            <td>/*Data to display actual result from database*/</td>
        </tr>
    </table>
</div>

      

I can't get a reference to the above table id "srchResultHeader" in my code? What's wrong here in my code.

+3


source to share


3 answers


An id

itself is only a client side identifier. In order to refer to this as a server object, it must be a server control. The easiest way is to add runat="server"

to an existing element:

<tr runat="server" id="srchResultHeader" style="display: none;" class="header" >

      



In this case, you probably don't even need the attribute style

, since you control the hide / show functionality in the server-side code. You can simply set .Visible

in the control to determine if it really refers to client side markup.

+10


source


.aspx

  <tr id="divDriverName1"  runat="server" >
<td >  
<label class=" ">label1 </label>
<asp:TextBox ID="TextBox1" runat="server" class=" form-control"></asp:TextBox>  
</td>  
</tr>

      



.aspx.cs

           ContentPlaceHolder myPlaceHolder = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1"); 
         HtmlTableRow ct = (myPlaceHolder.FindControl("divDriverName1")) as HtmlTableRow;
             divDriverName1.Attributes.Add("style", "display:none");

      

+1


source


You can use the server side <asp:Table>

for this purpose. Otherwise it <tr>

is a client-side thing and is not directly accessible in server-side code. <asp:Table>

will render the tag <table>

on the client side, but you can access it in code with ID

. The structure looks like this:

<asp:Table ID="MyTable" runat="server">
    <asp:TableRow runat="server" ID="MyRow1">
        <asp:TableCell>Some value<asp:TableCell>
    </asp:TableRow>
</asp:Table>

      

Now you can write something like this in your code:

MyRow1.Visible = False;

      

0


source







All Articles