1

I have a userControl "foo.ascx" registered on and loaded on index.aspx. On foo's page_load I am calling a javascript method which is created on foo's markup page. I am using Page.ClientScript.RegisterClientScriptBlock The problem I am running up against is, during the loading of the user control the ClientScriptBlock code seems to be calling the javascript before the javascript is rendered. Below is an example of the page source i have and the problem IS StartCounter("25:10"); IS being called before the function is created. Any help would be great. Thank you very much.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script type="text/javascript" src="Assets/Javascript/jQuery.js" ></script>
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head><title>
    </title></head>
    <body>
       <form name="form1" method="post" action="default.aspx" id="form1">
    <div>
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTUxOTYxMTY4OGRkounMyYFBle29baVV35X4KzMIHn4=" />
    </div>   
 <type="text/javascript">
//<![CDATA[
StartCounter("25:10");//]]>
   </script>
       <div>
    <script type="text/javascript" src="../Assets/Javascript/Timer.js"></script>
    <script type="text/javascript">
      $(document).ready(function() {
      });
    function StartCounter(startTime)
    {
      $('#counter').countdown({
        stepTime: 60,
        format: 'mm:ss',
        startTime: startTime,
        digitImages: 6,
        digitWidth: 53,
        digitHeight: 77,
        timerEnd: function() { alert('end!!'); },
        image: "/Assets/Images/digits.png"
      });
      }

1 Answer 1

2

Try to register the js in this way in RegisterClientScriptBlock from server side it will solve the problem.

$(document).ready(function(){ StartCounter("25:10"); });
Sign up to request clarification or add additional context in comments.

1 Comment

will do, they have a built in timer and need to wait another minute

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.