开发者

calling javascript From userControl

开发者 https://www.devze.com 2023-03-19 06:51 出处:网络
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 usin开发者_如何学Gog Page.Cl

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 usin开发者_如何学Gog 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"
      });
      }


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

$(document).ready(function(){ StartCounter("25:10"); });
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号