Learner
Learner

Reputation: 1634

The function client side is not working properly

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
    function abc()
    {
        return confirm('are U sure?');
    }
    </script>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="abc()" 
            onclick="Button1_Click" style="height: 26px" />
    
    </div>
    </form>
</body>
</html>

In the above page whether you click ok or cancel for confirmation box the processing transfer for server why?

Upvotes: 0

Views: 190

Answers (3)

gbs
gbs

Reputation: 7266

It should be like this:

 OnClientClick="return abc();"

Upvotes: 1

Mutation Person
Mutation Person

Reputation: 30500

As it is a server control, the submit even is being fired as well.

The return false (which you would get by clicking 'cancel') may stop the onclick event, however the onsubmit event is still being fired.

You could try capturing this instead of the onclick event.

Upvotes: 0

m.edmondson
m.edmondson

Reputation: 30892

If I understand the question correctly you are asking why when you click Button1 is it posting back to the server?

This is because its a server control.

If you want a simple client button it would look like the following:

<input type="button" value="Button" OnClick="abc()" style="height: 26px" />

This would mean no processing on the server.

Upvotes: 1

Related Questions