1

I am using OnTextChanged event of a TextBox run code behind if it lost focus , When the page is firstly load, it can trigger the behind code. However, after the first time running the behind code, if I go back to the textbox and make it lost focus again, it does not do any code behind again. How can I make the textbox trigger code behind each time it lost focus.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <telerik:RadTextBox ID="uiToLocation" runat="server" Width="100%" AutoPostBack="true"
                    OnTextChanged="uiToLocation_Leave" EmptyMessage="<%$ Resources:ResourceHKEx,Arrive_To %>" />
            </ContentTemplate>
        </asp:UpdatePanel>

The back code, main aspx.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Telerik.Web.UI;


namespace WebHKEx
{
    public partial class FlightEdit : Web.CustomPage
    {

        protected void Page_Init(object sender, EventArgs e)
        {
            // initialize variables
            InitializeVariables();

            // permission checking
            VerifyUserPermissions(true);

            // initialize controls
            InitializeControls();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Page_UnLoad(object sender, EventArgs e)
        {

        }        

    } // end class
} // end namespace

And the code behind is in a subcontrol cs file.

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace WebHKEx.WebControls
{
    public partial class UsageControl2SubControl1 : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Convert.ToBoolean(uiRemoved.Value))
            {
                this.Visible = false;
            }
        }

        protected void uiToLocation_Leave(object sender, EventArgs e)
        {
                uiDistance = "123";

        }
    }// end class
}// end namespace 

want_to_be_calm
  • 1,477
  • 3
  • 23
  • 41
  • Could you give your back code – evilGenius May 07 '19 at 08:08
  • In web form not exist implementation lose focus it can be make only js – evilGenius May 07 '19 at 08:32
  • the `OnTextChanged` is fired as its name suggest on every keystroke inside the textbox.. –  May 07 '19 at 08:32
  • are you updating/changing content of the textbox again and then change the focus out from the textbox? – Kevin Shah May 07 '19 at 09:55
  • 1
    @KevinShah I updating/changing the content of the textbox again and then change the focus out from the textbox, it triggers the code behind again. Thanks – want_to_be_calm May 07 '19 at 10:23
  • without any change in the textbox content event will not be trigger as View state value is not being updated so there is nothing to be post. – Kevin Shah May 07 '19 at 10:33
  • @KevinShah can I make it run the code behind just for change the focus out from the textBox? – want_to_be_calm May 08 '19 at 02:40
  • You can do that using javascript. on focus out you have to call javascript function and on that function you need to write code to call textchange event or you can call button click event – Kevin Shah May 08 '19 at 06:05

0 Answers0