How to check if a text field is really active or has focus?

In C #, is it possible to get the bool value by determining if the cursor is in a specific text field?

What I want to achieve:

I have a main page with two buttons; search button and login button. Depending on which text block is active or has focus, or if there is no focus, I want to set the UseSubmitBehavior attribute.

What I want is something like this (I know this code is not working):

if (textboxUsername.hasfocus == true || textboxPassword.hasfocus == true)
{
    buttonLogin.UseSubmitBehavior = true;
    buttonSearch.UseSubmitBehavior = false;
}
else
{
    buttonLogin.UseSubmitBehavior = false;
    buttonSearch.UseSubmitBehavior = true;
}

The goal is to make the page react as the user expects it, for example. it’s actually a search when you get to the input, and not an attempt to enter the system when you enter text in the search field.

+2
1

, , .

, DefaultButton.

<asp:Panel runat="server" ID="SearchPanel" DefaultButton="Search">
    <asp:TextBox runat="server" ID="SearchInput" />
    <asp:Button runat="server" ID="Search" />
</asp:Panel>

enter , .

: LinkButtons ImageButtons, , : : none; LinkButton Button .

+3

Source: https://habr.com/ru/post/1768511/


All Articles