ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Display Success Popup Box after record inserted using C# and VB.Net in ASP.Net<p>Hi&nbsp;nauna,</p> <p>Check this example. Now please take its reference and correct your code.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;table&gt; &lt;tr&gt; &lt;td&gt; Name &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtName&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Country &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox runat=&#34;server&#34; ID=&#34;txtCountry&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan=&#34;2&#34; align=&#34;center&#34;&gt; &lt;asp:Button Text=&#34;Save&#34; runat=&#34;server&#34; OnClick=&#34;Save&#34; /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js&#34;&gt;&lt;/script&gt; &lt;link type=&#34;text/css&#34; rel=&#34;stylesheet&#34; href=&#34;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css&#34; /&gt; &lt;style type=&#34;text/css&#34;&gt; .message { width: 100%; position: absolute; top: 10px; left: 50%; z-index: 100000; padding: 0; font-size: 15px; margin: 0 auto; } &lt;/style&gt; &lt;script type=&#34;text/javascript&#34;&gt; function ShowMessage(message, messagetype) { var cssclass; switch (messagetype) { case &#39;Success&#39;: cssclass = &#39;alert-success&#39; break; case &#39;Error&#39;: cssclass = &#39;alert-danger&#39; break; case &#39;Warning&#39;: cssclass = &#39;alert-warning&#39; break; default: cssclass = &#39;alert-info&#39; } $(&#39;body&#39;).append(&#39;&lt;div id=&#34;alert_div&#34; style=&#34;margin: 0 10%; -webkit-box-shadow: 3px 4px 6px #999;width:50%&#34; class=&#34;alert fade in &#39; + cssclass + &#39;&#34;&gt;&lt;a href=&#34;#&#34; class=&#34;close&#34; data-dismiss=&#34;alert&#34; aria-label=&#34;close&#34;&gt;&amp;times;&lt;/a&gt;&lt;strong&gt;&#39; + &#39;&lt;span&gt;&#39; + message + &#39;&lt;/span&gt;&lt;/div&gt;&#39;); } &lt;/script&gt;</pre> <p><strong><span style="text-decoration: underline;">Namespaces</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">using System.Configuration; using System.Data.SqlClient;</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Imports System.Configuration Imports System.Data.SqlClient</pre> <p><strong><span style="text-decoration: underline;">Code</span></strong></p> <p><strong>C#</strong></p> <pre class="brush: csharp">protected void Save(object sender, EventArgs e) { int i = 0; string conString = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; string query = &#34;INSERT INTO Customers VALUES(@Name,@Country)&#34;; SqlCommand cmd = new SqlCommand(query); SqlConnection con = new SqlConnection(conString); cmd.Connection = con; cmd.Parameters.AddWithValue(&#34;@Name&#34;, txtName.Text.Trim()); cmd.Parameters.AddWithValue(&#34;@Country&#34;, txtCountry.Text.Trim()); try { con.Open(); i = cmd.ExecuteNonQuery(); con.Close(); if (i &gt; 0) { ShowMessage(&#34;Record submitted successfully&#34;, MessageType.Success); } } catch (Exception ex) { } } public enum MessageType { Success, Error, Info, Warning }; protected void ShowMessage(string Message, MessageType type) { ScriptManager.RegisterStartupScript(this, this.GetType(), System.Guid.NewGuid().ToString(), &#34;ShowMessage(&#39;&#34; + Message + &#34;&#39;,&#39;&#34; + type + &#34;&#39;);&#34;, true); }</pre> <p><strong>VB.Net</strong></p> <pre class="brush: vb">Protected Sub Save(ByVal sender As Object, ByVal e As EventArgs) Dim i As Integer = 0 Dim conString As String = ConfigurationManager.ConnectionStrings(&#34;constr&#34;).ConnectionString Dim query As String = &#34;INSERT INTO Customers VALUES(@Name,@Country)&#34; Dim cmd As SqlCommand = New SqlCommand(query) Dim con As SqlConnection = New SqlConnection(conString) cmd.Connection = con cmd.Parameters.AddWithValue(&#34;@Name&#34;, txtName.Text.Trim()) cmd.Parameters.AddWithValue(&#34;@Country&#34;, txtCountry.Text.Trim()) Try con.Open() i = cmd.ExecuteNonQuery() con.Close() If i &gt; 0 Then ShowMessage(&#34;Record submitted successfully&#34;, MessageType.Success) End If Catch ex As Exception End Try End Sub Public Enum MessageType Success = 0 [Error] = 1 Info = 2 Warning = 3 End Enum Protected Sub ShowMessage(ByVal Message As String, ByVal type As MessageType) ScriptManager.RegisterStartupScript(Me, Me.GetType(), System.Guid.NewGuid().ToString(), &#34;ShowMessage(&#39;&#34; &amp; Message &amp; &#34;&#39;,&#39;&#34; &amp; type &amp; &#34;&#39;);&#34;, True) End Sub</pre> <p><span style="text-decoration: underline;"><strong>Screenshot</strong></span></p> <p><span style="text-decoration: underline;"><strong><img src="https://i.imgur.com/E9YcjTc.gif" alt="" width="249" height="207" /></strong></span></p>https://www.aspforums.net:443/Threads/768946/Display-Success-Popup-Box-after-record-inserted-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/768946/Display-Success-Popup-Box-after-record-inserted-using-C-and-VBNet-in-ASPNet/Fri, 30 Nov 2018 05:35:08 GMTDisplay Success Popup Box after record inserted using C# and VB.Net in ASP.Net<p>hello,&nbsp;</p> <p>it is good, can i define it in a class file.</p> <pre class="brush: csharp">public enum MessageType { Success, Error, Info, Warning }; protected void ShowMessage(string Message, MessageType type) { ScriptManager.RegisterStartupScript(this, this.GetType(), System.Guid.NewGuid().ToString(), &#34;ShowMessage(&#39;&#34; + Message + &#34;&#39;,&#39;&#34; + type + &#34;&#39;);&#34;, true); }</pre> <p>and on page i can just this method so it looks clean</p> <pre class="brush: csharp">ShowMessage(&#34;Record submitted successfully&#34;, MessageType.Success);</pre> <p>pls advice</p>https://www.aspforums.net:443/Threads/768946/Display-Success-Popup-Box-after-record-inserted-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/768946/Display-Success-Popup-Box-after-record-inserted-using-C-and-VBNet-in-ASPNet/Fri, 30 Nov 2018 08:39:18 GMTDisplay Success Popup Box after record inserted using C# and VB.Net in ASP.Net<p>Hi nauna,</p> <p>Yes you can.</p> <p>Follow the below steps.</p> <p>1. Create a class file and write the below code.</p> <pre class="brush: csharp">public class MessagePopup { private System.Web.UI.Page page; public MessagePopup(System.Web.UI.Page pages) { page = pages; } public void ShowMessage(string Message, string messageType) { if (messageType.ToLower() == &#34;success&#34;) { messageType = &#34;Success&#34;; } else if (messageType.ToLower() == &#34;error&#34;) { messageType = &#34;Error&#34;; } else if (messageType.ToLower() == &#34;info&#34;) { messageType = &#34;Info&#34;; } else if (messageType.ToLower() == &#34;warning&#34;) { messageType = &#34;Warning&#34;; } System.Web.UI.ScriptManager.RegisterStartupScript(page, this.GetType(), System.Guid.NewGuid().ToString(), &#34;ShowMessage(&#39;&#34; + Message + &#34;&#39;,&#39;&#34; + messageType + &#34;&#39;);&#34;, true); } }</pre> <p>2. Call the method using the below code in the page where you want to call.</p> <pre class="brush: csharp">MessagePopup messagePopup = new MessagePopup(this.Page); messagePopup.ShowMessage(&#34;Record submitted successfully&#34;, &#34;Success&#34;);</pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/768946/Display-Success-Popup-Box-after-record-inserted-using-C-and-VBNet-in-ASPNet/https://www.aspforums.net:443/Threads/768946/Display-Success-Popup-Box-after-record-inserted-using-C-and-VBNet-in-ASPNet/Sun, 02 Dec 2018 23:18:30 GMT