I encountered difficulties with the textbox textchange feature when working in ASP.NET using C#

I have a TextBox in my popup page. I need to determine if the text entered in the TextBox is "Admin" by using TextBox.Text.Equals("Admin");

Here is how the TextBox is defined:

<asp:TextBox ID="TextBox1" runat="server" Height="35px" 
      ontextchanged="TextBox1_TextChanged" AutoPostBack="true"
      style="text-align: right; font-size: x-large" Width="200px">
</asp:TextBox>

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
    if(TextBox1.Text.Equals("Admin"))
    {
        Page.ClientScript.RegisterOnSubmitStatement(typeof(Page), "closePage", "window.onunload = CloseWindow();");
    }
}

The function of TextBox1_TextChanged does not trigger when the text is changed.

I am looking for a way to automatically close the window when some text is entered. Can anyone provide assistance or suggest an alternative solution? I prefer not to require button click for closing.

(The text will be entered into the textbox via card reader, hence the need for automatic closure)

Thank you in advance.

Answer №1

In my opinion, handling the text changed event on the client side is crucial. Text content can be constantly changing and sending every key press to the server would significantly impact performance.

Answer №2

When using a textbox, the TextChanged Event will only trigger if you modify the content and then navigate away from the textbox. If text is inputted via a card reader, the cursor will stay within the textbox. To check if the TextChanged Event fires, try clicking outside the textbox or hitting Enter or Tab after entering text. Ensure that the textbox's text is not cleared in your Page_Load event if the event does fire. Remember the importance of understanding IsPostBack.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Vuetify autocomplete with server-side functionality

I am looking to implement infinite pagination on the Vuetify autocomplete feature. My goal is to trigger the loading of a new page of items from the backend when I scroll to the end of the menu. Initially, I attempted using the v-intersect directive as fo ...

Developing middleware for managing event handlers

Scenario: I am tasked with managing multiple events that necessitate an "available client". Therefore, in each event handler, my first step is to attempt to acquire an available client. If no client is available, I will send a "Service unavailable" messag ...

What is the best way to assign a background color to each tr element using JavaScript?

I have a list of table rows with different background colors like <tr bgcolor="#OC6110"> <tr bgcolor="#000000"> <tr bgcolor="#FFFFFF"> Is there a way to assign unique background colors to each tr element without specifying its id value ...

Is it possible to access specific elements of an array in Node.js by their index in the storage?

Just wanted to give a heads up - I’m still getting the hang of things, so there’s a chance my approach may not be quite right! I’ve got a Javascript application (in Node.js) that needs to fill up a database - specifically, it’s an array with 88 mi ...

Leveraging Ajax to send JSON data to PHP session

I am attempting to send some JSON data to a PHP file, which will then create a session. I have two different JSON blocks that need to be added to their respective PHP sessions. Could someone please assist me in finding the issue? The sessions are not bein ...

Organizing requirejs and angularjs code structure into separate files

Looking to organize my Angular application with requirejs by separating controllers, services, and directives into different files. Hoping to achieve this structure: src/ components/ Navigation/ index.js module.js NavigationCon ...

"Implementing automated default values for Select/dropdown lists in ReactJs, with the added capability to manually revert back to the default selection

After browsing multiple websites, I couldn't find a clear solution on how to both set and select a default value in a select element. Most resources only explain how to set the value, without addressing how to reselect the default value. My Requireme ...

Exploring the method of iterating through every single row, column, and cell within a GridView in ASP.NET to assign specific values

I am struggling to iterate through each row, column, and cell to populate a GridView with a list of employee objects. Each employee has an ID, name, and city, which should be displayed in separate columns. The first column should show the ID, the second co ...

How to create shapes with smooth edges in ThreeJS

I am attempting to create a shape using threeJS that consists of both straight and curved edges. Here is what I currently have: https://i.sstatic.net/9pK3g.jpg My goal is to connect the two top corners with a semicircle in order to achieve a square shape ...

Angular Inner Class

As a newcomer to Angular, I have a question about creating nested classes in Angular similar to the .NET class structure. public class BaseResponse<T> { public T Data { get; set; } public int StatusCo ...

Issue with Hover Effect on Safari Browser

Encountering a peculiar issue exclusively in Safari - when hovering over a link in the header, the links to the right of the hovered-over link alter their size (appearing smaller) during the hover animation. Once the animation concludes, these links revert ...

Tips for continuing a count from where it left off

I have encountered an issue with the input fields in my form. I used the counter method to add input fields and saved the form. However, when I try to add more fields, the counter starts from 0 again. For example, I initially added 5 input fields with mod ...

Am I utilizing React hooks correctly in this scenario?

I'm currently exploring the example, but I have doubts about whether I can implement it in this manner. import _ from "lodash"; ... let [widget, setWidgetList] = useState([]); onRemoveItem(i) { console.log("removing", i); ...

Sending Angular Material Select Option Value for Submission

HTML: <form id="reg" name="reg" enctype="application/x-www-form-urlencoded" action="http://api.phphotspot.com/v-2/client-register" method="post"> <md-input-container class="md-block"> <label for="country">Country</label&g ...

Tips for efficiently importing a file or folder that is valuable but not currently in use

I'm struggling to find any information about this particular case online. Perhaps someone here might have some insight. I keep getting a warning message saying 'FournisseursDb' is defined but never used no-unused-vars when I try to import t ...

Obtaining the local IP address of my system with React JS

Is there a way to retrieve the local IP of my computer within a React JS application? I would appreciate any suggestions on how to accomplish this. ...

Exploring the front side of a cube using three.js

Exploring the following example: I am curious to know whether it's possible to determine which side of the cube is facing the camera, i.e., the front side. So far, I have been unable to figure this out. Any assistance on this matter would be greatly ...

What are the steps to invoke a restful service with arguments in an ASP.NET web form?

I'm currently working on integrating a RESTful service into an asp.net webform using C#. I was able to successfully retrieve the Token using HttpWebRequest, but I encountered an issue when trying to call the service with parameters. In my attempt to s ...

"AngularJS Bi-Directional Data Binding Issue: Unexpected 'Undefined

Recently, I've been tackling a project that involves using a directive. Initially, everything was smooth sailing as I had my directive set up to bind to ngModel. However, I hit a roadblock when I needed to bind multiple values. Upon making the necessa ...

NextJs 13 encountered an issue locating the module path and was unable to resolve it

I encountered an error stating 'unable to resolve path to module' while working with NextJs version 13 `{ "extends": [ "next", "airbnb-base",`your text` "eslint:recommended", "plugin: ...