locked
textbox loose focus on OnTextChanged event and flicker on the page when postback occurs RRS feed

  • Question

  • User351619809 posted

    Hello All,

    I have the following code on my page. Whenever, user tab out of the field txtAddress, a textChanged event is triggered and the cursor looses the focus. I want to put the focus on next field after the txtAddress field. The next field is txtCity field. Also, although, I have a updatePanel around the txtAddress field, but still, I can see a postback when I tab out of txtAddress field by the flicker on the page and page scrolls up.

    	
    <asp:UpdatePanel ID="up1" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional"  >
                <ContentTemplate>
    <div style="width: 100%;" class="ui-block-a ui-margins" >
    	<label for="field_Address_DOT_Address1" class="required" >Address </label>
    				<asp:TextBox autocomplete="stop" maxlength="128" ID="txtShipAddress" runat="server" style="text-transform:uppercase;" OnTextChanged="txtAddressTextChanged" AutoPostBack="true" ></asp:TextBox>
    </div>
    				</ContentTemplate>
               <Triggers>
                     <asp:PostBackTrigger ControlID="txtShipAddress" />
               </Triggers>
             </asp:UpdatePanel>

     below is my code behind:

       protected void txtAddressTextChanged(object sender, EventArgs e)
            {
                if (POBoxValidator().Equals(1))
                {
                    pnlMessage.Visible = true;
                    
                }
                else
                {
                    pnlMessage.Visible = false;
                }
                SetFocus(txtCity);
                upPanel.Update();
                SetFocus(txtCity);
    			txtCity.Focus();
            }
    		

    Below is my pnlMessage code in aspx page:

    	    <asp:UpdatePanel runat="server" ID="upPanel" UpdateMode="Conditional" ChildrenAsTriggers="false" >
                <ContentTemplate>
    
    		<asp:Panel ID="pnlMessage" runat="server" Visible="false" >
    		<div  class="ui-radio ui-btn" style="font-size:20px;">
    			<span style="color:red"><b> Note: This is  a test message</b>  </span>
    		</div>
    
    	</asp:Panel>
       </ContentTemplate>
            </asp:UpdatePanel>

    any help will be greatly appreciated.

    Friday, February 12, 2021 7:32 PM

Answers

  • User1535942433 posted

    Hi anjaliagarwal5@yahoo.com,

    According to your description,I don't understand your purpose  of your codes.In your codes,you update the panel of "upPanel" and you don't want to postback the page. You need to add AsyncPostBackTrigger in the "upPanel".

    If you have problems,you could tell us more details to us.It will help us to solve your problems.

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 15, 2021 5:48 AM

All replies

  • User1535942433 posted

    Hi anjaliagarwal5@yahoo.com,

    According to your description,I don't understand your purpose  of your codes.In your codes,you update the panel of "upPanel" and you don't want to postback the page. You need to add AsyncPostBackTrigger in the "upPanel".

    If you have problems,you could tell us more details to us.It will help us to solve your problems.

    Best regards,

    Yijing Sun

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 15, 2021 5:48 AM
  • User351619809 posted

    AsyncPostBackTrigger worked right away. Thanks.

    Monday, February 15, 2021 6:13 AM