Answered by:
How To Refresh Page And Redirect To ABC.aspx page

Question
-
User-807418713 posted
Hello
I used this code below after alert message data saved
url: 'CustomerSale_Entry.aspx/InsertData', data: JSON.stringify({myModels:data}), success: function (e) { alert("Data Saved Sucessfully..."); },
I want to refresh the existing page and open new tab abc.aspx
And New tab open should be in 300px window size.
Thank You
Friday, June 14, 2019 4:35 AM
Answers
-
User665608656 posted
Hi Gopi.MCA,
According to your description, are you using Ajax and asking webmethod to add data?
To refresh the page after alert and open another page, you only need to add a statement to refresh the page after the alert.
I did an example of adding data with the same function. You coudl refer to the following code:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="../Scripts/jquery-1.10.2.min.js"></script> <script> $(function () { $("#Button2").click(function () { var name = $("#name").val(); var age = $("#age").val(); var depositAmount = $("#depositAmount").val(); var withDrawAmount = $("#withDrawAmount").val(); $.ajax({ type: "POST", url: "WebForm_0614_2156630.aspx/InsertData", contentType: 'application/json; charset=utf-8', dataType: 'json', data: '{Name: "' + name + '",Age:"' + age + '",DepositAmount:"' + depositAmount + '",WithDrawAmount:"' + withDrawAmount + '" }', success: function (result) { $("#name").val(""); $("#age").val(""); $("#depositAmount").val(""); $("#withDrawAmount").val(""); alert("Data Saved Sucessfully..."); location.reload(); window.open('ABC.aspx', '', 'height=300,width=300,scrollbars=yes,status =yes'); } }); return false; }); }) </script> </head> <body> <form id="form1" runat="server"> <asp:GridView runat="server" AutoGenerateColumns="False" ID="Gridview1"> <Columns> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" /> <asp:BoundField DataField="DepositAmount" HeaderText="DepositAmount" SortExpression="DepositAmount" /> <asp:BoundField DataField="WithDrawAmount" HeaderText="WithDrawAmount" SortExpression="WithDrawAmount" /> </Columns> </asp:GridView> <br /> <br /> <div id="tableId"> Add Data: <table border="1" style="border-collapse: collapse"> <tr> <th>Name</th> <th>Age</th> <th>DepositAmount</th> <th>WithDrawAmount</th> <th></th> </tr> <tr> <td> <asp:TextBox ID="name" runat="server"></asp:TextBox></td> <td> <asp:TextBox ID="age" runat="server"></asp:TextBox></td> <td> <asp:TextBox ID="depositAmount" runat="server"></asp:TextBox></td> <td> <asp:TextBox ID="withDrawAmount" runat="server"></asp:TextBox></td> <td> <asp:Button ID="Button2" runat="server" Text="Add" /></td> </tr> </table> </div> </form> </body> </html>
code behind:
using System; using System.Collections.Generic; using System.Configuration; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1.Cases { public partial class WebForm_0614_2156630 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { List<Entity> employeeList = new List<Entity>(); SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); conn.Open(); SqlCommand cmd = new SqlCommand("select * from Entity", conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { var employeeSet = new Entity() { Name = Convert.ToString(reader["Name"]), Age = Convert.ToString(reader["Age"]), DepositAmount = Convert.ToString(reader["DepositAmount"]), WithDrawAmount = Convert.ToString(reader["WithDrawAmount"]), }; employeeList.Add(employeeSet); } reader.Close(); conn.Close(); Gridview1.DataSource = employeeList; Gridview1.DataBind(); } } [WebMethod] public static void InsertData(string Name, string Age, string DepositAmount, string WithDrawAmount) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); conn.Open(); SqlCommand cmd = new SqlCommand("Insert into Entity values (@Name,@Age,@DepositAmount,@WithDrawAmount)", conn); cmd.Parameters.AddWithValue("@Name", Name); cmd.Parameters.AddWithValue("@Age", Age); cmd.Parameters.AddWithValue("@DepositAmount", DepositAmount); cmd.Parameters.AddWithValue("@WithDrawAmount", WithDrawAmount); cmd.ExecuteNonQuery(); conn.Close(); } } public class Entity { public string Name { get; set; } public string Age { get; set; } public string DepositAmount { get; set; } public string WithDrawAmount { get; set; } } }
Here is the result of this work demo:
Best Regards,
YongQing.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 14, 2019 9:10 AM
All replies
-
User-1038772411 posted
Hi, Gopi.MCA
Once the page is rendered to the client you have only two ways of forcing a refresh. One is Javascript
setTimeout("location.reload(true);", timeout);
The second is a Meta tag:
<meta http-equiv="refresh" content="600">
You can set the refresh intervals on the server side.
Response.Redirect(//Pass url as you want to redirect.);
Code :
setTimeout(function () { window.location.reload(); }, 1000); Response.Redirect(Url.Action("ActionMethod", "Controller"));
Friday, June 14, 2019 6:58 AM -
User665608656 posted
Hi Gopi.MCA,
According to your description, are you using Ajax and asking webmethod to add data?
To refresh the page after alert and open another page, you only need to add a statement to refresh the page after the alert.
I did an example of adding data with the same function. You coudl refer to the following code:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="../Scripts/jquery-1.10.2.min.js"></script> <script> $(function () { $("#Button2").click(function () { var name = $("#name").val(); var age = $("#age").val(); var depositAmount = $("#depositAmount").val(); var withDrawAmount = $("#withDrawAmount").val(); $.ajax({ type: "POST", url: "WebForm_0614_2156630.aspx/InsertData", contentType: 'application/json; charset=utf-8', dataType: 'json', data: '{Name: "' + name + '",Age:"' + age + '",DepositAmount:"' + depositAmount + '",WithDrawAmount:"' + withDrawAmount + '" }', success: function (result) { $("#name").val(""); $("#age").val(""); $("#depositAmount").val(""); $("#withDrawAmount").val(""); alert("Data Saved Sucessfully..."); location.reload(); window.open('ABC.aspx', '', 'height=300,width=300,scrollbars=yes,status =yes'); } }); return false; }); }) </script> </head> <body> <form id="form1" runat="server"> <asp:GridView runat="server" AutoGenerateColumns="False" ID="Gridview1"> <Columns> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" /> <asp:BoundField DataField="DepositAmount" HeaderText="DepositAmount" SortExpression="DepositAmount" /> <asp:BoundField DataField="WithDrawAmount" HeaderText="WithDrawAmount" SortExpression="WithDrawAmount" /> </Columns> </asp:GridView> <br /> <br /> <div id="tableId"> Add Data: <table border="1" style="border-collapse: collapse"> <tr> <th>Name</th> <th>Age</th> <th>DepositAmount</th> <th>WithDrawAmount</th> <th></th> </tr> <tr> <td> <asp:TextBox ID="name" runat="server"></asp:TextBox></td> <td> <asp:TextBox ID="age" runat="server"></asp:TextBox></td> <td> <asp:TextBox ID="depositAmount" runat="server"></asp:TextBox></td> <td> <asp:TextBox ID="withDrawAmount" runat="server"></asp:TextBox></td> <td> <asp:Button ID="Button2" runat="server" Text="Add" /></td> </tr> </table> </div> </form> </body> </html>
code behind:
using System; using System.Collections.Generic; using System.Configuration; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1.Cases { public partial class WebForm_0614_2156630 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { List<Entity> employeeList = new List<Entity>(); SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); conn.Open(); SqlCommand cmd = new SqlCommand("select * from Entity", conn); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { var employeeSet = new Entity() { Name = Convert.ToString(reader["Name"]), Age = Convert.ToString(reader["Age"]), DepositAmount = Convert.ToString(reader["DepositAmount"]), WithDrawAmount = Convert.ToString(reader["WithDrawAmount"]), }; employeeList.Add(employeeSet); } reader.Close(); conn.Close(); Gridview1.DataSource = employeeList; Gridview1.DataBind(); } } [WebMethod] public static void InsertData(string Name, string Age, string DepositAmount, string WithDrawAmount) { SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); conn.Open(); SqlCommand cmd = new SqlCommand("Insert into Entity values (@Name,@Age,@DepositAmount,@WithDrawAmount)", conn); cmd.Parameters.AddWithValue("@Name", Name); cmd.Parameters.AddWithValue("@Age", Age); cmd.Parameters.AddWithValue("@DepositAmount", DepositAmount); cmd.Parameters.AddWithValue("@WithDrawAmount", WithDrawAmount); cmd.ExecuteNonQuery(); conn.Close(); } } public class Entity { public string Name { get; set; } public string Age { get; set; } public string DepositAmount { get; set; } public string WithDrawAmount { get; set; } } }
Here is the result of this work demo:
Best Regards,
YongQing.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 14, 2019 9:10 AM