c# - How to check to see if a textbox is currently active or has focus? -
in c#, possible bool value, determining if cursor inside textbox?
what want achieve:
i have masterpage, 2 buttons in it; search-button , login-button. depending on textbox active or has focus, or of none have focus, want set usesubmitbehavior-attribute.
what want happen (i know code doesn't work):
if (textboxusername.hasfocus == true || textboxpassword.hasfocus == true) { buttonlogin.usesubmitbehavior = true; buttonsearch.usesubmitbehavior = false; } else { buttonlogin.usesubmitbehavior = false; buttonsearch.usesubmitbehavior = true; }
the goal make page react way user expect to, e.g. searching when hitting enter, , not trying login, when typing in search-field.
what trying won't work that.
what can enclosing login fields in panel , search field in panel, , add defaultbutton both of them.
<asp:panel runat="server" id="searchpanel" defaultbutton="search"> <asp:textbox runat="server" id="searchinput" /> <asp:button runat="server" id="search" /> </asp:panel>
if press enter in textbox search button postback.
note: not work linkbuttons or imagebuttons, if use these can add workaround: add normal button , set it's style display:none; , let linkbutton , button trigger same event.
Comments
Post a Comment