title: Code Behind calling a JavaScript function on a button click - C#
body: <p>I have a Js function which calls the bootstrap modal popup. I'm calling this Js function from code behind on a button click. The problem is when I click on the button it is showing the modal popup, but when I navigate to another page(When I click on another button,It navigates to a google document reader) and come back to the home page, it is again loading the popup without any button click. Can anyone help me with this.</p>
  
  <h3>JS function</h3>
  
  <pre><code>&lt;head&gt;
   &lt;script type="text/javascript"&gt;
              function showModal() {
                  $('#viewOc').modal();
              };
      &lt;/script&gt;
  &lt;/head&gt;
  </code></pre>
  
  <h3>Modal Popup code</h3>
  
  <pre><code> &lt;div class="modal fade" id="viewOc" role="dialog"&gt;
          &lt;div class="modal-dialog"&gt;
              &lt;div class="modal-content"&gt;
                  &lt;div class="modal-header"&gt;
                      &lt;h4&gt;TRIAL&lt;/h4&gt;
                  &lt;/div&gt;
                  &lt;div class="modal-body"&gt;
                      LOREM IPSUM
                  &lt;/div&gt;
                  &lt;div class="modal-footer"&gt;
                      &lt;a class="btn btn-primary" data-dismiss="modal"&gt;
                          Close
                      &lt;/a&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <h3>Code behind</h3>
  
  <pre><code> protected void LinkButton1_Click(object sender, CommandEventArgs e)
              {
                  //some operations here
                  string script = "window.onload = function() { showModal(); };";
                  ClientScript.RegisterStartupScript(this.GetType(), "modalShow", script, true); 
              }
  </code></pre>
  
  <h3>Html code</h3>
  
  <pre><code>&lt;asp:LinkButton ID="LinkButton1" runat="server" Text="Click Here" CausesValidation="false" commandArgument='&lt;%#Eval("value")%&gt;' OnCommand="LinkButton1_Click"/&gt;
  </code></pre>
  
  <h3>Google Docs button click event</h3>
  
  <pre><code> protected void btnView_View(object sender, CommandEventArgs e)
          {
              //not sure if the below code is correct or wrong. But as of now im using this in my application. Didnt try it on server yet.
              string path = e.CommandArgument.ToString();
              Response.Redirect("http://docs.google.com/viewer?url=" + Server.UrlEncode(path),true);
          }
  </code></pre>
  
  <h3>Page Load</h3>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
          {
              if (!IsPostBack)
              {
                  IndexDocuments();
  
              }
          }
  </code></pre>
  
  <p>P.S : I know similar question but with a different problem is asked in SO. As I dont have enough reputation to comment on that question, I had to make a new post. </p>