epaezr
epaezr

Reputation: 474

how to call a JS function on a asp:LinkButton click event

I have this JS function that loads whenever the page loads:

<script type="text/javascript">

    window.onload = function () {
        <asp:Literal ID="LiteralGraph01" runat="server"></asp:Literal>
        <asp:Literal ID="LiteralGraph_ft01" runat="server"></asp:Literal>


</script>

How can I invoke this function from a asp:LinkButton click? The link button is called filtroCombinado:

<asp:LinkButton ID="filtroCombinado" runat="server"></asp:LinkButton>

Thanks for your help!

Upvotes: 0

Views: 1178

Answers (2)

Pankaj Toshniwal
Pankaj Toshniwal

Reputation: 197

Try this:

    <script type="text/javascript">

       var onLoadFunction = function () {
            <asp:Literal ID="LiteralGraph01" runat="server"></asp:Literal>
            <asp:Literal ID="LiteralGraph_ft01" runat="server"></asp:Literal>


    </script>

<asp:LinkButton ID="filtroCombinado" runat="server" onClientClick="onLoadFunction()"></asp:LinkButton>

Upvotes: 1

Alex Kudryashev
Alex Kudryashev

Reputation: 9460

<asp:LinkButton... is rendered as an anchor (<a href=...). If you want to run some JS onload and onclick do something like this.

<script type="text/javascript">

window.onload = function myFunc () {//nobody blames you when you name the function
    <asp:Literal ID="LiteralGraph01" runat="server">some data I fill in from server (and replace this text)</asp:Literal>
    <asp:Literal ID="LiteralGraph_ft01" runat="server"></asp:Literal>
    return false; //avoid sending request to the server
}//close the function
</script>
...
//do something before sending request to the server
<asp:LinkButton ID="filtroCombinado" runat="server" OnClientClick="return myFunc();"></asp:LinkButton>

Upvotes: 1

Related Questions