0

In asp.net Project, firstly I have to hide the table row and when click on linkbutton then show this table row. So I call a function on OnClientClick of link button with name ShowDiv. Now issue is that after calling that function, It again go to document.readyfunction.

    <script type="text/javascript">
    $(document).ready(function () {
        $("#trUpdateImportEmail").hide();
    });
    function ShowDiv() {
        $("#trUpdateImportEmail").show()
    }
</script>

 <asp:LinkButton ID="lnkUpdateEmail" runat="server" CausesValidation="False" CommandName="Select" Text='Update Import Email' OnClientClick="Show()"></asp:LinkButton>

2 Answers2

2

In your code document is reloaded on click button. So prevent document reload by using return false or event.preventdefault() in your function.

  <script type="text/javascript">
$(document).ready(function () {
    $("#trUpdateImportEmail").hide();
});
function ShowDiv() {
    $("#trUpdateImportEmail").show();
    return false;
}

Or

  <script type="text/javascript">
$(document).ready(function () {
    $("#trUpdateImportEmail").hide();
});
function ShowDiv(event) {
    event.preventdefault();
    $("#trUpdateImportEmail").show();
}

1

Because asp:LinkButton is a server side control, it will eventualy postback. when your debugger "jumps" again to the document.ready, it because the page has probably been reloaded.

when using OnClientClick, it doesn't replace the LinkButton behavior (i.e postback), it just runs before it.

try returning false from the js function (because it returns true). and let your OnClientClick look like:

return ShowDiv();
TTomer
  • 356
  • 2
  • 11