In my C# i used this code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ASPConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
}
protected void SubmitButtonClick(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("INSERT INTO Students (Name,City,Age) Values(@Name,@City,@Age)", con);
cmd.Parameters.AddWithValue("@Name", NameText.Text);
cmd.Parameters.AddWithValue("@City", CityText.Text);
cmd.Parameters.AddWithValue("@Age", Convert.ToInt32(AgeText.Text));
cmd.ExecuteNonQuery();
con.Close();
SuccessMessage.Visible = true;
SuccessMessage.Text = "Successfully Inserted data";
CityText.Text = "";
NameText.Text = "";
AgeText.Text = "";
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "showalert();", true);
}
}
And my ASPX:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1
{
text-align: center;
}
.auto-style2
{
width: 163px;
}
.auto-style3
{
text-align: center;
}
.auto-style4
{
font-size: large;
}
.auto-style5
{
text-align: right;
}
.auto-style6
{
width: 112px;
}
.auto-style7
{
text-align: center;
width: 163px;
}
</style>
</head>
<body>
<div id="dialog" title="Basic dialog">
<p>insert succussfly</p>
</div>
<button id="opener">Open Dialog</button>
<form id="form1" runat="server">
<div>
<div class="auto-style3">
<span class="auto-style4">Inserting Data to DB<br />
</span>
</div>
<table align="center" style="width: 41%; height: 179px;">
<tr>
<td class="auto-style5">Name:</td>
<td class="auto-style6">
<asp:TextBox ID="NameText" runat="server"></asp:TextBox>
</td>
<td class="auto-style2">
<asp:RequiredFieldValidator ID="NameValidation" runat="server"
ControlToValidate="NameText" ErrorMessage="Name is reqiured"
Style="color: #FF0000; text-align: left">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style5">City:</td>
<td class="auto-style6">
<asp:TextBox ID="CityText" runat="server"></asp:TextBox>
</td>
<td class="auto-style2"> </td>
</tr>
<tr>
<td class="auto-style5">Age:</td>
<td class="auto-style6">
<asp:TextBox ID="AgeText" runat="server"></asp:TextBox>
</td>
<td class="auto-style2">
<asp:RangeValidator ID="AgeValidation" runat="server"
ControlToValidate="AgeText" Display="Dynamic"
ErrorMessage="Age need to be between 20 to 50" MaximumValue="50"
MinimumValue="20" Style="color: #CC0000">*</asp:RangeValidator>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="AgeText" Display="Dynamic" ErrorMessage="Age is required"
Style="color: #CC0000">*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style1" colspan="2">
<asp:Button ID="SubmitButton" runat="server" OnClick="SubmitButtonClick"
Style="text-align: center" Text="Insert" />
</td>
<td class="auto-style7"> </td>
</tr>
</table>
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
Style="color: #CC0000" />
<asp:Label ID="SuccessMessage" runat="server" Text="" Visible="False"></asp:Label>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ASPConnectionString %>"
SelectCommand="SELECT * FROM [Students]"></asp:SqlDataSource>
</form>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function () {
$("#dialog").dialog({
autoOpen: false,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
function showalert() {
$(document).ready(function () {
$("#dialog").dialog("open");
});
}
/* $("#opener").click(function () {
$("#dialog").dialog("open");
});*/
});
</script>
</body>
</html>
I want to open the dialog after postback and it runs the alert function after finished the insert. Can you help me thanks. I'm now getting showalert() is not defined.