Display success message using JavaScript alert after Form submission in ASP.Net

micah
 
on Aug 13, 2015 02:31 AM
16384 Views

Hi i got this code on this forum on how to display message using modal popup. But i want to use it on displaying data submitted successfully when a user is submitting record. Nomally i use this:

 

ScriptManager.RegisterClientScriptBlock(btnSave, this.GetType(), "alert", "<script>alert('Please quantity required is more than the stock, Stock is 1 or less than 1, update stock ... !!')</script>", false);

But now i want to use this

 

   <script type="text/javascript">
                       $("[id*=btnSave]").live("click", function () {
                           $("#dialog").dialog({
                               title: "jQuery Dialog Popup",
                               buttons: {
                                   Close: function () {
                                       $(this).dialog('close');
                                   }
                               }
                           });
                           return false;
                       });
</script>
<div id="dialog" style="display: none">
    Data Submitted Successfully
</div>

I have tried this javascript methode and my button wasn't submmitting any record. Please how do i use that to make it work?

Download FREE API for Word, Excel and PDF in ASP.Net: Download
manvendra45
 
on Aug 13, 2015 04:02 AM
on Aug 13, 2015 04:10 AM

hi micah try this code

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
 <link type="text/css" rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>


    <script type="text/javascript">
        function Getlogmodel()  {
            $("#popupdiv").dialog({
                title: "write here text from  Getlogmodel java script code",
                width: 430,
                height: 250,
                modal: true,
                buttons: {
                    Close: function () {
                        $(this).dialog('close');
                    }
                }
            });
            return false;
        };
        function Getlogmodel2() {
            $("#popupdiv2").dialog({
                title: "write here text from  Getlogmodel2 java script code",
                width: 430,
                height: 250,
                modal: true,
                buttons: {
                    Close: function () {
                        $(this).dialog('close');
                    }
                }
            });
            return false;
        };

</script>

<body>
    <form id="form1" runat="server">
   <div>
<div id="popupdiv" title="" style="display: none">
<b> Data are  correct</b>
</div>

       <div id="popupdiv2" title="" style="display: none">
<b> Data are  incorrect</b>
</div>
<table align="center" style="margin-top:200px">
<tr>
<td>


    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" 
        style="height: 26px" />
</td>
</tr>
</table>

</div>
    </form>
</body>
</html>

c # code

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

             string a = "33a";
            if(a=="a")
            {

                 ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "Getlogmodel();", true);
            }
             else if (a !="a")
            {

                ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "Getlogmodel2();", true);

            }
       
    }
}

may be helpfull for you