Is there a way to call/run JavaScript from C#?
<p>I have a C# function in which I would like to call/run some JavaScript:</p>

<pre><code>protected void DetailsView1_DataBound(object sender, EventArgs e) {
   ...
   // call/run JavaScript
   ...
}
</code></pre>

<p>I'm dealing with a form, specifically, submitting the form. Upon clicking "Submit", several C# functions run that take care of validation and other miscellaneous tasks. After these are done, I need to run some JavaScript but I'm having trouble synchronizing these events. The JavaScript is:</p>

<pre><code>...
if (uploader.total.uploaded == 0) {
   if (uploader.files.length &gt; 0) {
      uploader.start();
   }
   e.preventDefault();
}
...
</code></pre>

<p>The way I've been trying to do this is by detecting the click event on the "Submit" button via jQuery and running my Javascript, but then the form itself doesn't submit. I've tried variations of this but I haven't had luck.</p>

<p>So how would I accomplish this? Is "RegisterClientScript" something that I should look into? If so, would a possible solution be registering the JavaScript on PageLoad and attaching it to the Submit button? If so, how would I do this in code?</p>

<p>Let me know if I need to further clarify my question.</p>

<h2>UPDATE</h2>

<p>A bit of clarification... the form on this page is submitted by a button:</p>

<pre><code>&lt;asp:CommandField ValidationGroup="request" ButtonType="Image" 
        CancelText="Reset" CancelImageUrl="../images/internal/btn_reset.gif"
        InsertImageUrl="../images/internal/btn_insert.gif" ShowEditButton="True" 
        ShowInsertButton="True" /&gt;
</code></pre>

<p>This creates 2 buttons, the Insert being the Submission button so I refer to it as the Submit button.</p>

<p>Thanks,<br />
Hristo</p>
