title: How to Invoke Button click Event of .ascx after checking timeout value using Javascript on its .aspx File
body: <ul>
  <li>I have 2 Files. One is aspx and its ascx.</li>
  <li>aspx contains Javascript which calculates count down time for exam.</li>
  <li>while timer value reaches to 00:00:00 I want to invoke an event "Submit Exam" which is in ascx file.</li>
  </ul>
  
  <blockquote>
    <p>Final Paper.aspx.cs</p>
  </blockquote>
  
  <pre><code>public partial class Final_Paper : System.Web.UI.Page 
  {
      long timerStartValue = 600;
  
      protected void Page_Load(object sender, EventArgs e)
      {            
          if (!Page.IsPostBack)
          {
              this.timerStartValue = long.Parse(ConfigurationManager.AppSettings["Delay"].ToString());
              this.TimerInterval = 500;
          }
      }
  
      public string message()
      {
          string val;
          val = Request.Form["timerData"].ToString();
          TimeSpan ts = TimeSpan.FromMilliseconds(Convert.ToDouble(val.ToString()));
          return ts.ToString();            
      }
  
      void Page_PreRender(object sender, EventArgs e)
      {
          StringBuilder bldr = new StringBuilder();            
          bldr.AppendFormat("var Timer = new myTimer({0},{1},'{2}','timerData');", this.timerStartValue, this.TimerInterval, this.lbltime.ClientID);
          bldr.Append("Timer.go()");
          Page.ClientScript.RegisterStartupScript(this.GetType(), "TimerScript", bldr.ToString(), true);
          Page.ClientScript.RegisterHiddenField("timerData", timerStartValue.ToString());
      }
  
      void Page_PreInit(object sender, EventArgs e)
      {
          string timerVal = Request.Form["timerData"];
          if (timerVal != null || timerVal == "")
          {
              timerVal = timerVal.Replace(",", String.Empty);
              timerStartValue = long.Parse(timerVal);
          }
      }
  
      private Int32 TimerInterval
      {
          get
          {
              object o = ViewState["timerInterval"];
              if (o != null) { return Int32.Parse(o.ToString()); }
              return 50;
          }
          set { ViewState["timerInterval"] = value; }
  
      }
  
  }
  </code></pre>
  
  <blockquote>
    <p>Final Paper.aspx</p>
  </blockquote>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function myTimer(startVal, interval, outputId, dataField) {
          this.value = startVal;
          this.OutputCntrl = document.getElementById(outputId);
          this.currentTimeOut = null;
          this.interval = interval;
          this.stopped = false;
          this.data = null;
          var formEls = document.form1.elements;
          if (dataField) {
              for (var i = 0; i &lt; formEls.length - 1; i++) {
                  if (formEls[i].name == dataField) {
                      this.data = formEls[i];
                      i = formEls.length + 1;
                  }
              }
          }
  
          myTimer.prototype.go = function() {
              if (this.value &gt; 0 &amp;&amp; this.stopped == false) {
                  this.value = (this.value - this.interval);
                  if (this.data) {
                      this.data.value = this.value;
                  }
                  var current = this.value;
                  this.OutputCntrl.innerHTML = this.Hours(current) + ':' + this.Minutes(current) + ':' + this.Seconds(current);
                  this.currentTimeOut = setTimeout("Timer.go()", this.interval);
              }
              else {                
                  alert('Time Out!');
                  window.location('index.aspx');
              }
  
  
  
          }
          myTimer.prototype.stop = function() {
              this.stopped = true;
              if (this.currentTimeOut != null) {
                  clearTimeout(this.currentTimeout);
              }
          }
          myTimer.prototype.Hours = function(value) {
              return Math.floor(value / 3600000);
          }
          myTimer.prototype.Minutes = function(value) {
              return Math.floor((value - (this.Hours(value) * 3600000)) / 60000);
          }
          myTimer.prototype.Seconds = function(value) {
              var hoursMillSecs = (this.Hours(value) * 3600000)
              var minutesMillSecs = (this.Minutes(value) * 60000)
              var total = (hoursMillSecs + minutesMillSecs)
              var ans = Math.floor(((this.value - total) % 60000) / 1000);
  
              if (ans &lt; 10)
                  return "0" + ans;
  
              return ans;
          }
      }           
  
  
  
  &lt;/script&gt;
  </code></pre>
  
  <blockquote>
    <p>Exam_paper.ascx</p>
  </blockquote>
  
  <pre><code>protected void btnSubmit_Click(object sender, EventArgs e)
      {
          lbTime.Text = ((Final_Paper)this.Page).message();
          foreach (ListViewItem item in paper_list.Items)
          {
              RadioButton ansA = (RadioButton)item.FindControl("ansA");
              RadioButton ansB = (RadioButton)item.FindControl("ansB");
              RadioButton ansC = (RadioButton)item.FindControl("ansC");
              RadioButton ansD = (RadioButton)item.FindControl("ansD");
              Label rightAns = (Label)item.FindControl("rightAns");
  
  
              if (ansA.Checked &amp;&amp; rightAns.Text == "ansA")
              {
                  a = a + 1;
              }
              else if (ansB.Checked &amp;&amp; rightAns.Text == "ansB")
              {
                  a = a + 1;
              }
              else if (ansC.Checked &amp;&amp; rightAns.Text == "ansC")
              {
                  a = a + 1;
              }
              else if (ansD.Checked &amp;&amp; rightAns.Text == "ansD")
              {
                  a = a + 1;
              }
              else
              {
                  a = a + 0;
              }
          }
  
          marks = (float)2 * (float)a;
  
          addResult();
  
          Session.Remove("stud");
          if (Session["stud"] == null)
          {
              Response.Redirect("index.aspx");
          }            
  
      }
  </code></pre>