0

suppose i have a create form and with button save data in database and i want to show that save successfully in div tag using JavaScript but when i click button then at a time on event work but not 2 event onclick and onClientClick ..

<here>
<asp:Button runat="server" CssClass="myButton" Text="Registration"  ID="btnRegistration" OnClick="btnRegistration_Click "  OnClientClick="return YourJavaScriptFunction();" Height="65px" Width="184px" ClientIDMode="Predictable"></asp:Button>

and   
<script type="text/javascript">

        function YourJavaScriptFunction() {
            $("#message").slideDown("slow");

            // this will prevent the postback, equivalent to: event.preventDefault();
            return false;

        }
</script>

I want that first data saved then work onClientClick event in one asp:button

DhruvJoshi
  • 17,041
  • 6
  • 41
  • 60
  • 2
    possible duplicate of [Asp .NET Button - OnClientClick="return function()" vs OnClientClick="function()"](http://stackoverflow.com/questions/20028858/asp-net-button-onclientclick-return-function-vs-onclientclick-function) – MethodMan Aug 10 '15 at 21:15

2 Answers2

1

You need to tell your Javascript code to display the message on page load after the button click postback event happens.

There are many ways to accomplish this.

One way is through a session

aspx code with js:

<% if(Session["ShowMessage"] != null){ %>
   $("#message").slideDown("slow");
<% } %>

Code behind on Page_Load:

Session["ShowMessage"] = null; //This will make sure that only the button will set the session state

on Button Click event

Session["ShowMessage"] = "Not null";

Another way is to Add Client Script Dynamically to ASP.NET Web Page

boruchsiper
  • 2,016
  • 9
  • 29
  • 53
0

as @boruchsiper suggested, I will go for the second option by calling registerclientscriptblock after the postback has successfully completed.

Anant Anand Gupta
  • 650
  • 1
  • 11
  • 22