title: RegisterStartupScript only runs the first time. ASP.NET C# JavaScript
body: <p>I have an .aspx page with the following code</p>
  
  <pre><code>&lt;asp:Panel runat="server" ID="ImagePanel"&gt;
     &lt;asp:UpdatePanel runat="server" ID="ImageUpdatePanel" UpdateMode="Conditional"&gt;&lt;ContentTemplate&gt;      
        &lt;img id="photo" src="/Icons/Factory Layout.png" style="display: none;"/&gt;
        &lt;script type="text/javascript"&gt;
            function ResetImage(typeOfImage) {
                var factoryImage = $("#photo");  
                  if (typeOfImage === 1) {
                      factoryImage.attr("src",document.getElementById('&lt;%= FactoryImageFileNameHF.ClientID %&gt;').value);
                  }
                  else if (typeOfImage === 2) {
                      factoryImage.attr("src",document.getElementById('&lt;%= IncidentFactoryImageFileNameHF.ClientID %&gt;').value);
                  }
  </code></pre>
  
  <p>It is the ResetImage <code>javascript</code> function that I am trying to run with the following code in the code behind.</p>
  
  <pre><code>if (typeOfMap == 1)
  {
       FactoryImageFileNameHF.Value = fileNameOfFactoryImage.FileFullPath();
       ClientScript.RegisterStartupScript(Page.GetType(), "test" + ScriptKeyHF.Value, "ResetImage(1);", true);
       ScriptKeyHF.Value = (ScriptKeyHF.Value.ToInt() + 1).ToString();
   }
   else if (typeOfMap == 2)
   {
        IncidentFactoryImageFileNameHF.Value = fileNameOfFactoryImage.FileFullPath();
        ClientScript.RegisterStartupScript(Page.GetType(), "test" + ScriptKeyHF.Value, "ResetImage(2);", true);
        ScriptKeyHF.Value = (ScriptKeyHF.Value.ToInt() + 1).ToString();
    }
  </code></pre>
  
  <p>The problem is that the ResetImage() method that I am calling in the <code>RegisterStartUpScript</code> only runs the first time on the browser. It doesn't run the second and third time of postbacks, etc. 
  I have tried the <code>RegisterClientScriptBlock</code> but it runs before the <code>javascript</code> code is there. Does anyone have any idea why the code only runs the first time.</p>