ASP.NET count boxes and then execute popup from same button
<p>Ok, I hope I can explain this well enough.</p>

<p>I have one or more third party Up/Down Spinner+Textbox controls on my page that are black boxes that I can't change the source for.</p>

<p>I want the user to change the UpDownControl contents to choose a quantity and then click a calendar button which will:</p>

<ol>
<li>Add the quantity of all Up/Down boxes.</li>
<li>Call a javascript popup to display a calendar with the count from step 1 in the url "...calendar.asp?qty=5".</li>
</ol>

<p>My problem is getting the two steps to execute in the same click.  As it stands I can click the button once and it counts 
the items and adds them to the popup string and then I have to click it a second time to actually execute the JS popup window.</p>

<p>The code was originally written to "load up" the counts into a second button and then programmatically click it but that looks
like a popup to the browsers since the user didn't click <em>that</em> button.</p>

<p>Here is what I have so far that almost works --</p>

<p>On my page:</p>

<pre><code>&lt;asp:ImageButton ID="btnPrepCal" runat="server" Text="PrepCal" OnClick="btnPrepCal_Click" ImageUrl="~/images/Calendar.gif"/&gt;        
</code></pre>

<p>In code behind:</p>

<pre><code>public void btnPrepCal_Click(object sender, EventArgs e)
{
StringBuilder sbParams = new StringBuilder();  

int TotalQty = 0;
int basketItemCount = 0;
int rowIndex = 0;
string Sku = string.Empty;

foreach (GridViewRow varRow in VariantGrid.Rows)
{
    int qnty = GetControlValue(varRow, "Quantity", 0);
    if (qnty &gt; 0)
    {
        basketItemCount++;
        string optionList = (string)VariantGrid.DataKeys[rowIndex].Value;
        ProductVariant variant = _VariantManager.GetVariantFromOptions(optionList);

        if (variant != null)
        {
            BasketItem basketItem = GetBasketItem(optionList, varRow);      
            if (basketItem != null)
            {
                TotalQty += basketItem.Quantity;                    
                Sku = variant.Sku;                          
            }
        }
    }
    rowIndex++;
}
if(Sku.Length &gt; 4) Sku = Sku.Substring(0,4);
sbParams.Append(string.Format("?sku={0}&amp;Qty={1}", Sku, TotalQty));
string popup = string.Empty;
popup = string.Format("window.open('http://trustedtours.org/store/egalaxycalendar.asp{0}','Reservation Calendar','width=265,height=465')",sbParams.ToString());
btnPrepCal.OnClientClick = popup;
</code></pre>

<p>}</p>

<p>I'm new to .NET and web programming so I'm probably going at it totally backwards so any help is appreciated.  I apologize if it's not clear what I'm trying to do or how.  If you need any more info please ask - the rest of the file is a lot of shopping cart mumbo jumbo so I left it out, I hope it's enough.</p>

<p>---- <strong>update</strong> ----
After looking at the referenced pages I get:</p>

<pre><code>Type cstype = this.GetType();
ClientScriptManager cs = Page.ClientScript;             
StringBuilder cstext1 = new StringBuilder();
cstext1.Append("&lt;script type=text/javascript&gt;" + popup + "&lt;script&gt;");
cs.RegisterStartupScript(cstype, "PopupCalendar", cstext1.ToString());
</code></pre>

<p>And I believe this is added after I set the value of popup near the bottom of my Click handler above, removing the OnClientClick part, right? </p>

<p>Should this popup the other window on a page reload after clicking the button?  (I hate being a newb and asking what's probably obvious questions.)</p>
