tags:

views:

67

answers:

4

I have a simple table

<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table> 

and a link

<a href=#>Click me</a> 

Is it possible to make the whole block of html code disappear all in once after clicking the link in c#? I was thinking about a placeholder but i'm not sure

A: 

set an ID on a span surrounding your table and one on your link and use JQuery to handle this :

$("#btnId").click(function() {$("#tableId").html(""); });
VdesmedT
jquery seems overkill for something simple like that if it isn't there already. Just using simple javascript is allowed
Raynos
+1  A: 
<div id="hide">
<table border="1">
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table> 
<a href=# onclick="getElementById('hide').style.display = 'none'">Click me</a> 
</div>

Wrapped in a div and handle onclick to make the div hide. Good luck getting it back

Raynos
A: 

You can use ids and jQuery to hide your table. This is useful if you want to show it again later, not delete the content.

<table id="myTable" border="1">...</table>

<a id="hideLink" href=#>Hide Table</a>

<a id="showLink" href=#>Show Table</a>

<script language="JavaScript">

jQuery(#hideLink).onClick(function(){
  jQuery(#myTable).hide();
});

jQuery(#showLink).onClick(function(){
  jQuery(#myTable).show();
});

</script>
Thomas Langston
+2  A: 

Using C# (as opposed to client script):

a LinkButton will render an HTML a tag with a javascript: PostBack function call. (This is still relying on JavaScript. Use a Button for no client script dependency, that will render an HTML submit input).

<%@ Page Language="C#" %>

<script runat="server">
    protected void MyLink_Click(object sender, EventArgs e)
    {
        MyTable.Visible = false;
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<body>
    <form runat="server">
    <table id="MyTable" border="1" runat="server">
        <tr>
            <td>
                row 1, cell 1
            </td>
            <td>
                row 1, cell 2
            </td>
        </tr>
        <tr>
            <td>
                row 2, cell 1
            </td>
            <td>
                row 2, cell 2
            </td>
        </tr>
    </table>
    <asp:LinkButton ID="MyLink" Text="Hide table" runat="server" OnClick="MyLink_Click" />
    </form>
</body>
</html>
langsamu