Click here to Skip to main content
15,893,644 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi..
My question is how can i set priority of tow function/method on one button click.I have one java script function call and one method is code behind.I want when i click on button then first javascript function call,its takes value and then other function call which is code behind,on single button click(ASP.NET ,C#)

What I have tried:

Here is my code aspx :
ASP.NET
<script type="text/javascript">
    function myFunction() {
        var person = prompt("Enter Table Name");

        if (person != null) {
            document.getElementById("txtName").innerHTML = person;
       
        }
    }
</script>
Table Name<asp:TextBox ID="txtName" runat="server" Width="146px"></asp:TextBox>
 <asp:Button ID="Button2" ValidationGroup="s" runat="server" onclick="insert" Text="Create Table" /> //'insert '(code behind method) i want first myfunction call then "insert" method call.

How can i do this?
Posted
Updated 17-Apr-16 20:45pm
Comments
Sergey Alexandrovich Kryukov 17-Apr-16 14:58pm    
There is no such thing as priority in call. The question makes no sense. What you call will be called in order you call it.
—SA

1 solution

What you are looking for in OnClientClick attribute of asp:Button

You need to write as below:

ASP.NET
<asp:Button ID="Button2" ValidationGroup="s" runat="server" onclick="insert" Text="Create Table" onClientClick="myFunction()" />
 
Share this answer
 
Comments
That's correct. Take a 5. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900