1

Hi that's a simple code that I saw in my asp.net course references...

I don't understand something in the property onClientClick:

onClientClick = "myClick(); return false;"

Why in this case (or eventually other cases) it's important to finish the JavasScript calls with the "return false;" after the myClick() function?

What's the logic behind that?

Thx Guys!

<script type = "text/javascript">

    function myClick() {
        alert("Hello");
    }  
</script>



<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" Height="202px" Width="349px">
            <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" Text="Click me" onClientClick = "myClick(); return false;" />
                </ItemTemplate> 
            </asp:TemplateField> 
                <asp:BoundField DataField="Id" HeaderText="Id"  />
                <asp:BoundField DataField="Family" HeaderText="Family"  />
                <asp:BoundField DataField="Name" HeaderText="Name"  />
            </Columns>
        </asp:GridView>

    </div>
    </form>
</body>
</html>
1
  • thanks! I found good infos there! Commented Oct 14, 2013 at 15:40

1 Answer 1

2

It prevents the default action of the link from taking place, which would most likely be a quick post back. This can also be accomplished with preventDefault (https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.