title: Implementing javascript confirm box in code behind on drop down box's selected index change event firing
body: <p>Inside my boxLang_OnSelectedIndexChanged() event I got this :-</p>
  
  <pre><code> if (txtbox1.Text != "" &amp;&amp; txtbox2.Text  != "")
          {
              ScriptManager.RegisterStartupScript(Page, Page.GetType(), "confirm", "confirm('Changing the language will clear the text in the textboxes. Click OK to proceed.');", true);
              txtbox1.Text = "";
              txtbox2.Text = "";
          }
  </code></pre>
  
  <p>Now what is happening is that. When I select a different item from the drop down list this confirm box does show up BUT it first clears the content of the text boxes and then this confirm box appears. What I want is that the textboxes content should be cleared ONLY when OK is clicked.</p>
  
  <p>What am I doing wrong? Please help.Thanks.</p>
  
  <p>edit
  @jgauffin
  <strong>** I typed return where you have. Now what is happening is that its just clearing the textboxes right away..didn't even show the confirm box this time! Whats wrong now?? Please reply..thnx**</strong></p>
  
  <p><strong>edit 2
  I tried as follows:-</strong></p>
  
  <p>Inside my BindDropDown() method I added :-</p>
  
  <pre><code>dropdownbox1.Attributes.Add("onChange","DisplayConfirmation()");
  </code></pre>
  
  <p>then in my aspx page I have added the following script as follows:-</p>
  
  <pre><code>&lt;script type="css/javascript"&gt;
  function DisplayConfirmation() {
    if (confirm('Changing the language will clear the text in the textboxes. Click OK to proceed.')) {
      __doPostback('dropdownbox1','');
    }
  }
  
  &lt;/script&gt;
  </code></pre>
  
  <p>This function is not getting called when drop down's selected index is changed. What's wrong?</p>
  
  <p><strong>edit 3:-
  ok I changed the line of code as follows:-</strong></p>
  
  <pre><code> dropdownbox1.Attributes.Add("onchange", "javascript:return DisplayConfirmation()");
  </code></pre>
  
  <p>Still wont work. I am new to JavaScript and all so having problems. Help will be much appreciated.</p>