Hi..
I need to check if a textbox has focus in it? How to check if a textbox has focus through c# code?
-
-
check "IsFocused" property...
TextBox tb = new TextBox();
if(tb.IsFocused)
{
your code here
.....
.....
} -
hi..
I am using ASP.NET 2.0 with c#. I didnt get any property called IsFocused().
My scenario is this. I have a web application which has a button and several textboxes. The button name is New. In one of the textboxes, i have the default text as hh:mm:ss.
<asp:TextBox ID="txtStartTime" runat="server" Width="96px" TabIndex="14" MaxLength="8" Text="hh:mm:ss"></asp:TextBox>
Now when the user clicks the New Button, i am changing the name of the button as Save. At this point, the textbox value which had default text as hh:mm:ss is not present. so i manually puttxtStartTime.Text = "hh:mm:ss"; in my aspx.cs code
Now when the focus reaches this textbox, i need to clear the default text value?
How to clear this value,when the user has focus in the textbox? -
<asp:TextBox ID="txtStartTime" runat="server" Width="96px" TabIndex="14" MaxLength="8" Text="hh:mm:ss" onlick="javascript:this.value='';"></asp:TextBox>
Sheva -
have you tried the MaskedEdit control of the asp.net ajax toolkit? it does what you've described
-
footballism wrote:<asp:TextBox ID="txtStartTime" runat="server" Width="96px" TabIndex="14" MaxLength="8" Text="hh:mm:ss" onlick="javascript:this.value='';"></asp:TextBox>
Sheva
onlick?
While this works, it only handles the mouse click event, which really isn't focus. Users may tab to the control and click isn't raised, the solution is pretty simple really, onclick should become onfocus, but if an ajax extended control exists that already composites this functionality, it should probably be used.
As a side note to the thread author, it would be nice if you responded to peoples help rather than just sitting aparently waiting for the answer, its insulting when you ask people for help and don't respond, you may as well just start a thread asking someone to do your entire 'job' for you.... -
He did respond.
-
onclick handles more than just click events.
There's also the onfocus and onactivate events.
Other things being equal, I would recommend onfocus, which has the benefit of being standard HTML. -
ZippyV wrote:He did respond.
http://channel9.msdn.com/ShowPost.aspx?PostID=306732
http://channel9.msdn.com/ShowPost.aspx?PostID=305454
http://channel9.msdn.com/ShowPost.aspx?PostID=305234
http://channel9.msdn.com/ShowPost.aspx?PostID=303682
http://channel9.msdn.com/ShowPost.aspx?PostID=303450
http://channel9.msdn.com/ShowPost.aspx?PostID=303265
http://channel9.msdn.com/ShowPost.aspx?PostID=302467
http://channel9.msdn.com/ShowPost.aspx?PostID=301835
http://channel9.msdn.com/ShowPost.aspx?PostID=301833
http://channel9.msdn.com/ShowPost.aspx?PostID=299535
http://channel9.msdn.com/ShowPost.aspx?PostID=299389
http://channel9.msdn.com/ShowPost.aspx?PostID=305234http://channel9.msdn.com/ShowPost.aspx?PostID=303682http://channel9.msdn.com/ShowPost.aspx?PostID=303450http://channel9.msdn.com/ShowPost.aspx?PostID=303265http://channel9.msdn.com/ShowPost.aspx?PostID=302467http://channel9.msdn.com/ShowPost.aspx?PostID=301835http://channel9.msdn.com/ShowPost.aspx?PostID=301833http://channel9.msdn.com/ShowPost.aspx?PostID=299535http://channel9.msdn.com/ShowPost.aspx?PostID=299389">
-
stevo_ wrote:

ZippyV wrote:
He did respond.
http://channel9.msdn.com/ShowPost.aspx?PostID=306732
http://channel9.msdn.com/ShowPost.aspx?PostID=305454
http://channel9.msdn.com/ShowPost.aspx?PostID=305234
http://channel9.msdn.com/ShowPost.aspx?PostID=303682
http://channel9.msdn.com/ShowPost.aspx?PostID=303450
http://channel9.msdn.com/ShowPost.aspx?PostID=303265
http://channel9.msdn.com/ShowPost.aspx?PostID=302467
http://channel9.msdn.com/ShowPost.aspx?PostID=301835
http://channel9.msdn.com/ShowPost.aspx?PostID=301833
http://channel9.msdn.com/ShowPost.aspx?PostID=299535
http://channel9.msdn.com/ShowPost.aspx?PostID=299389
So true... and sometimes just some simple search would do it... there are so many search engines available... for example google
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.