How to run a javascript function before postback of asp.net button?
<p>I'm using Javascript to create a DIV element and open up a new page by using onclientclick. This works great. Now, I need to write to it from the server side and this element must be created before it is posted back.</p>

<p>How do I get the javascript to execute before the postback?</p>

<p>Currently, I have to press the button twice because the element doesn't exist to write too on the first click.</p>

<p>To be clear, I need this to execute before the "OnClick" of the button.</p>

<p>Update: It looks like the Javascript function is called before the postback but the element is not updated until I run the second postback. Hmm</p>

<p>Update: Unfortunately it is a bit more complicated then this.</p>

<p>I'm creating a div tag in javascript to open a new window. Inside the div tag, I'm using a databinding syntax &lt;%=Preview%> so that I can get access to this element on the server side. From the server side, I'm injecting the code.</p>

<p>I'm thinking this may be a chicken-egg problem but not sure.</p>

<p>UPDATE!</p>

<p>It is not the Javascript not running first. It is the databinding mechanism which is reading the blank variable before I'm able to set it.</p>

<p>Hmm</p>
