0

Hi ,

Basically I want to display a popup box only at a specific time in asp.net application. so i'm using the following code..

aspx page :

<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
function timedMsg()
{
var t=setTimeout("alert('good morning!')",6000);
}
</script>
</head>

C# code :

protected void Button1_Click(object sender, EventArgs e)
    {
        StringBuilder script = new StringBuilder();
        script.Append("<script type=\"text/javascript\">");
        script.Append("timedMsg();");
        script.Append("</script>");
        Page.ClientScript.RegisterClientScriptBlock(typeof(object), "JavaScriptBlock", script.ToString());
    }

this works fine but i dont want to set settimeout as fixed as 6000. i need to retrieve value from database and assign it to settimeout. so i modified the coding as below..

aspx page :

<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript">
function timedMsg(var x)
{
var t=setTimeout("alert('I am displayed after 3 seconds!')",x);
}
</script>
</head>

C# code :

protected void Button1_Click(object sender, EventArgs e)
    {
        int x = 6000;
        StringBuilder script = new StringBuilder();
        script.Append("<script type=\"text/javascript\">");
        script.Append("timedMsg("+x+");");
        script.Append("</script>");
        Page.ClientScript.RegisterClientScriptBlock(typeof(object), "JavaScriptBlock", script.ToString());
    }

but this code is not working. the alert box is not popping up. is this a correct method to pass values to the script?. or what else to be done to meet the requirement?.. pls help me..

thanks..

Edited by __avd: Added [code] tags.

2
Contributors
1
Reply
4
Views
7 Years
Discussion Span
Last Post by Tarang
0

This code works fine for me....

Javascript

<script language="javascript" type="text/javascript">
        function timedMsg(x)
        {
            var t=setTimeout("alert('I am displayed after 3 seconds!')",x);
        }
    </script>

Button Click Code :

int x = 6000;
        string s="timedMsg('"+x+"')";
        ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", s, true);

Edited by __avd: Added [code] tags.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.