Remove controls between postback

(JQUERY)


Hi,
In this article i am removing the table control in the client side using jquery, then i store the removed control id in hiddenfield, between the postback i retrieve the deleted control id from hidden field on document. ready function and remove it before loading the page.

.aspx Page

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../Scripts/jquery-1.9.1.js"></script>
    <script type="text/javascript">
        function removeControl() {
            var div = $('#div_cntr');

            var tbl = $(div).find('#tbl_product');

            $(tbl).remove();

            $('#hdn_rmvdcntr').val('#tbl_product');
           
        }

        $(function () {

            //between postbacks
            var div = $('#div_cntr');

            var tbl = $(div).find($('#hdn_rmvdcntr').val());

            if (tbl != null) {
                $(tbl).remove();
            }
        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div id="div_cntr">
    
        <asp:HiddenField ID="hdn_rmvdcntr" runat="server" />
      

      <table id="tbl_product">
          <tr>
              <td>table1,cell1</td>
              <td>table1,cell2</td>
          </tr>
      </table>
        <br />
          <table id="tbl_region">
          <tr>
              <td>table2,cell1</td>
              <td>table2,cell2</td>
          </tr>
      </table>
      
        <input type="submit" value="Press Submit After deletion" />
        <input type="button" value="Remove" id="btn_remove" onclick="removeControl();" />
  
    </div>
    </form>
</body>
</html>


Image

Ratings


Average Rating: 0.00 by 0 users
Giri Prasad
7/4/2013
7/4/2013
Download PDF

Comments