Popupextender with textbox, Unable to clear textbox

Last post 10-25-2007 3:51 PM by DisturbedBuddha. 5 replies.

Sort Posts:

  • Popupextender with textbox, Unable to clear textbox

    10-25-2007, 12:58 PM
    • Member
      116 point Member
    • miltonsnider
    • Member since 11-15-2006, 7:55 PM
    • Washington DC
    • Posts 294

    I would like toI put two textboxes into an update panel so that they when either text changes, the emailtextbox is cleared(purple text below).  The code in purple is not happening.  The emailtextbox is what a popupextender and radiobuttonlist is applied to.  AJAX knows the two texboxes are updating since the radiobuttonlist is updated, but why doesn't the emailtextbox get cleared.  The code is in the same place.  
     

        Protected Sub lastTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lastTextBox.TextChanged
            emailTextBox.Text = ""
            Dim UP1 As UpdatePanel = CType(FindControl("updatepanel1"), UpdatePanel)
            Dim RB1 As RadioButtonList = CType(UP1.FindControl("radiobuttonlist1"), RadioButtonList)
            RB1.DataBind()
        End Sub
    
        Protected Sub firstTextBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles firstTextBox.TextChanged
            emailTextBox.Text = ""
            Dim UP1 As UpdatePanel = CType(FindControl("updatepanel1"), UpdatePanel)
            Dim RB1 As RadioButtonList = CType(UP1.FindControl("radiobuttonlist1"), RadioButtonList)
            RB1.DataBind()
        End Sub

     

    regards
    Milton
  • Re: Popupextender with textbox, Unable to clear textbox

    10-25-2007, 1:33 PM

    The TextChanged event of the TextBox server control is only fired after a postback.  It then looks to see if the text property of the textbox has changed.  It is not something that happens in response to the user just typing in the textbox.  You can give the textbox an onkeyup attribute (<asp:TextBox ID="TextBox1" runat="server" onkeyup="clearEmail();" />).

    <script language="javascript" type="text/javascript">   
        function clearEmail() {
            document.getElementById('emailTextBox').value = '';
        }
    </script>

    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


    My latest ASP.NET AJAX blog entries.
  • Re: Popupextender with textbox, Unable to clear textbox

    10-25-2007, 2:34 PM
    • Member
      116 point Member
    • miltonsnider
    • Member since 11-15-2006, 7:55 PM
    • Washington DC
    • Posts 294

    I decided to use the onChange event for the textbox to run the javascript.  The key was learning that the ontextchange event won't happen.  Is there a way for the same javascript to tell the radiobuttonlist to bind from the lastTextbox.  The radiobuttonlist datasource uses the lastTextbox value as a parameter.  Now that the lastTextbox is empty, I need for the readiobuttonlist to refresh its data. 

    regards
    Milton
  • Re: Popupextender with textbox, Unable to clear textbox

    10-25-2007, 3:07 PM
    Answer

    No, javascript can only manipulate those document objects on the page.  I has not control over server interactions.  However, what you can do is cause a postback, during which the radio controls will rebind.  The javascript should be something along these lines: 

    <script language="javascript" type="text/javascript">
       
    function clearEmail() {
            document.getElementById(
    'TextBox2').value = '';
            __doPostBack(
    'TextBox1', '');
        }
    </script>

    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


    My latest ASP.NET AJAX blog entries.
  • Re: Popupextender with textbox, Unable to clear textbox

    10-25-2007, 3:28 PM
    • Member
      116 point Member
    • miltonsnider
    • Member since 11-15-2006, 7:55 PM
    • Washington DC
    • Posts 294

    That does it. Thanks.  Just to be clear, the _doPostBack... causes the entire page to postback, right?

    regards
    Milton
  • Re: Popupextender with textbox, Unable to clear textbox

    10-25-2007, 3:51 PM
    Answer

    Yes, but you could easily set this up as a partial-postback scenario: 

    • Place the radio lists in an updatepanel(s).
    • Set the event target of the __doPostBack() call as an asynch target of the updatepanel(s).

    For further details, read http://encosia.com/2007/07/13/easily-refresh-an-updatepanel-using-javascript/.

     

    ------------------------------------------------------
    If this post help you, please mark as "Answer".

    When you ask a question, remember to click "mark as answered" when you get a reply which answers your question.


    My latest ASP.NET AJAX blog entries.
Page 1 of 1 (6 items)