Auto Close Pop up after some second (like alert not page) [Resolved]

Posted by Nksingh420 under JavaScript on 5/8/2014 | Points: 10 | Views : 7442 | Status : [Member] | Replies : 3
i have one form and after submission that page i want to show message box and redirect to other page.
when i use alert i have to click "ok".
is there any alternative with out alert box ?




Responses

Posted by: Allemahesh on: 5/8/2014 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Dear Singh,

I am relay happy to review my java-script and JQuery concept to answer this question.

Here I have used JQuery dialog and setTimeout() functions to achieve your requirement.
Just run the below code in visual studio and you will get you popup.

Here is the solution:-

Default.aspx:-

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>jQuery UI Dialog - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">

<script type="text/javascript" language="javascript">
function showAlert() {
$("#dialog").dialog();
setTimeout(TimeOut, 5000); //1000 ms = 1 second
}
function TimeOut() {
$("#dialog").dialog("close");
//window.location = "Your redirect URL";
}
</script>

</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
<div id="dialog" title="Alert" style="display: none;">
<p>
Set you message here.</p>
</div>
</form>
</body>
</html>


Default.aspx.cs:-

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

}
protected void btnSubmit_Click(object sender, EventArgs e)
{
//Do you Insert logic.
ClientScript.RegisterStartupScript(typeof(Page), "Test", "<script type='text/javascript'>showAlert();</script>");
}
}


Happy Coding.

Nksingh420, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chandradev819 on: 5/9/2014 [Member] Starter | Points: 25

Up
0
Down

You also refer this thread
http://forums.asp.net/t/1818619.aspx?close+alert+window+automatically+after+5+seconds

Thanks and Regards
Chandradev
My Blog

Nksingh420, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sajjadhira on: 8/30/2017 [Member] Starter | Points: 25

Up
0
Down
This is an example of JavaScript automatic popup closing after 10 seconds with countdown,
<p style="text-align:center">This window will close automatically within <span id="counter">10</span> second(s).</p>
<script type="text/javascript">



function countdown() {

var i = document.getElementById('counter');

i.innerHTML = parseInt(i.innerHTML)-1;

if (parseInt(i.innerHTML)<=0) {

window.close();

}

}

setInterval(function(){ countdown(); },1000);

</script>

I have found it in this https://phpans.com/javascript-close-window-automatically-after-10-seconds/ . Hope this will be helpful for you.

Nksingh420, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response