473,387 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Removing default textbox data on click

Hi,

I have a textbox with the words "Enter your name here" inserted as default
text - At the moment, to remove this the user must highlight all the text
and delete before they type in their name - I've seen sites where all this
text dissapears as soon as the user clicks on it - how do I do that ?

Thanks

Jane
Nov 20 '05 #1
10 8992
you can use the GotFocus event of the textbox
"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@hercules.btinternet.com...
Hi,

I have a textbox with the words "Enter your name here" inserted as default
text - At the moment, to remove this the user must highlight all the text
and delete before they type in their name - I've seen sites where all this
text dissapears as soon as the user clicks on it - how do I do that ?

Thanks

Jane

Nov 20 '05 #2
While I probably wouldn't normally hardcode a string literal, this should
give you the idea to get started.

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "Enter your name here" Then
TextBox1.Text = ""
End If
End Sub

Or, to keep the default text there until they start typing:
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "Enter your name here" Then
TextBox1.SelectAll()
End If
End Sub
"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@hercules.btinternet.com...
Hi,

I have a textbox with the words "Enter your name here" inserted as default
text - At the moment, to remove this the user must highlight all the text
and delete before they type in their name - I've seen sites where all this
text dissapears as soon as the user clicks on it - how do I do that ?

Thanks

Jane

Nov 20 '05 #3
Thanks, I was going to ask for a pointer..... now I'm going to ask for
another !

I get this error...

Handles clause requires a WithEvents variable

Jane

"Philip Rieck" <st***@mckraken.com> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
While I probably wouldn't normally hardcode a string literal, this should
give you the idea to get started.

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "Enter your name here" Then
TextBox1.Text = ""
End If
End Sub

Or, to keep the default text there until they start typing:
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "Enter your name here" Then
TextBox1.SelectAll()
End If
End Sub
"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@hercules.btinternet.com...
Hi,

I have a textbox with the words "Enter your name here" inserted as default text - At the moment, to remove this the user must highlight all the text and delete before they type in their name - I've seen sites where all this text dissapears as soon as the user clicks on it - how do I do that ?

Thanks

Jane


Nov 20 '05 #4
To create the "GotFocus" handler automatically, do this: drag your textbox
to the form, and give it a name (in the designer). The default name will be
TextBox1 for the first text box.

Go to the code view, and in the left-hand dropdown just above the code,
select "TextBox1", or whatever you named it. Then in the righ-hand
dropdown, select the "GotFocus" item (it will have a little lightning bolt
next to it). This will create the Shell of the event handler.

In the code I sent, it assumes that the text box was named TextBox1. If it
wasnt, change the part that says
.... "Handles TextBox1.GotFocus "
To "Handles TheRealNameOfMyTextBox.GotFocus".

By named, I mean this : in the designer of your form, select the text box.
Look in the properties window and find the "(name)" property. Whatever is
entered there is the "name" of the text box that I keep referring to.


"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@sparta.btinternet.com...
Thanks, I was going to ask for a pointer..... now I'm going to ask for
another !

I get this error...

Handles clause requires a WithEvents variable

Jane

"Philip Rieck" <st***@mckraken.com> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
While I probably wouldn't normally hardcode a string literal, this should
give you the idea to get started.

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "Enter your name here" Then
TextBox1.Text = ""
End If
End Sub

Or, to keep the default text there until they start typing:
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "Enter your name here" Then
TextBox1.SelectAll()
End If
End Sub
"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@hercules.btinternet.com...
Hi,

I have a textbox with the words "Enter your name here" inserted as

default text - At the moment, to remove this the user must highlight all the text and delete before they type in their name - I've seen sites where all this text dissapears as soon as the user clicks on it - how do I do that ?

Thanks

Jane



Nov 20 '05 #5
And there probably lies my problem, I'm not developing in studio, just
writing code !

"Philip Rieck" <st***@mckraken.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
To create the "GotFocus" handler automatically, do this: drag your textbox
to the form, and give it a name (in the designer). The default name will be TextBox1 for the first text box.

Go to the code view, and in the left-hand dropdown just above the code,
select "TextBox1", or whatever you named it. Then in the righ-hand
dropdown, select the "GotFocus" item (it will have a little lightning bolt
next to it). This will create the Shell of the event handler.

In the code I sent, it assumes that the text box was named TextBox1. If it wasnt, change the part that says
... "Handles TextBox1.GotFocus "
To "Handles TheRealNameOfMyTextBox.GotFocus".

By named, I mean this : in the designer of your form, select the text box.
Look in the properties window and find the "(name)" property. Whatever is
entered there is the "name" of the text box that I keep referring to.


"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@sparta.btinternet.com...
Thanks, I was going to ask for a pointer..... now I'm going to ask for
another !

I get this error...

Handles clause requires a WithEvents variable

Jane

"Philip Rieck" <st***@mckraken.com> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
While I probably wouldn't normally hardcode a string literal, this should give you the idea to get started.

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "Enter your name here" Then
TextBox1.Text = ""
End If
End Sub

Or, to keep the default text there until they start typing:
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "Enter your name here" Then
TextBox1.SelectAll()
End If
End Sub
"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@hercules.btinternet.com...
> Hi,
>
> I have a textbox with the words "Enter your name here" inserted as

default
> text - At the moment, to remove this the user must highlight all the

text
> and delete before they type in their name - I've seen sites where all
this
> text dissapears as soon as the user clicks on it - how do I do that

? >
> Thanks
>
> Jane
>
>



Nov 20 '05 #6
when defining your textbox add withevents keyword:
private WithEvents myTextbox As TextBox
other solution:

private myTextbox As TextBox
Public Sub New()
addHandler myTextbox.GotFocus, AddressOf TextBox1_GotFocus
End Sub

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs)
....
End Sub
or something that looks alike ;-)

"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@titan.btinternet.com...
And there probably lies my problem, I'm not developing in studio, just
writing code !

"Philip Rieck" <st***@mckraken.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
To create the "GotFocus" handler automatically, do this: drag your textbox
to the form, and give it a name (in the designer). The default name will
be
TextBox1 for the first text box.

Go to the code view, and in the left-hand dropdown just above the code,
select "TextBox1", or whatever you named it. Then in the righ-hand
dropdown, select the "GotFocus" item (it will have a little lightning
bolt next to it). This will create the Shell of the event handler.

In the code I sent, it assumes that the text box was named TextBox1. If

it
wasnt, change the part that says
... "Handles TextBox1.GotFocus "
To "Handles TheRealNameOfMyTextBox.GotFocus".

By named, I mean this : in the designer of your form, select the text box. Look in the properties window and find the "(name)" property. Whatever is entered there is the "name" of the text box that I keep referring to.


"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@sparta.btinternet.com...
Thanks, I was going to ask for a pointer..... now I'm going to ask for
another !

I get this error...

Handles clause requires a WithEvents variable

Jane

"Philip Rieck" <st***@mckraken.com> wrote in message
news:eH**************@tk2msftngp13.phx.gbl...
> While I probably wouldn't normally hardcode a string literal, this

should
> give you the idea to get started.
>
> Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles TextBox1.GotFocus
> If TextBox1.Text = "Enter your name here" Then
> TextBox1.Text = ""
> End If
> End Sub
>
> Or, to keep the default text there until they start typing:
> Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles TextBox1.GotFocus
> If TextBox1.Text = "Enter your name here" Then
> TextBox1.SelectAll()
> End If
> End Sub
>
>
> "Jane Sharpe" <JS**@hotmail.com> wrote in message
> news:bu**********@hercules.btinternet.com...
> > Hi,
> >
> > I have a textbox with the words "Enter your name here" inserted as
default
> > text - At the moment, to remove this the user must highlight all the text
> > and delete before they type in their name - I've seen sites where

all this
> > text dissapears as soon as the user clicks on it - how do I do
that ? > >
> > Thanks
> >
> > Jane
> >
> >
>
>



Nov 20 '05 #7
Thanks for all this help, but I just CANT get this all to gel.

With this test code, I get the error

BC30590: Event 'GotFocus' cannot be found.
Heres my test code:-

<%@ Page Language="VB" %>

<script runat="server">

Private WithEvents TextBox1 As TextBox
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "Enter your name here" Then
TextBox1.Text = ""
End If
End Sub

</script>

<html>

<body>
<form Id="frmForm1" runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server" BorderStyle="Solid"
Enter your name here</asp:TextBox> </p>
</form>
</body>
</html>

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:O2**************@TK2MSFTNGP10.phx.gbl... when defining your textbox add withevents keyword:
private WithEvents myTextbox As TextBox
other solution:

private myTextbox As TextBox
Public Sub New()
addHandler myTextbox.GotFocus, AddressOf TextBox1_GotFocus
End Sub

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs)
...
End Sub
or something that looks alike ;-)

"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@titan.btinternet.com...
And there probably lies my problem, I'm not developing in studio, just
writing code !

"Philip Rieck" <st***@mckraken.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
To create the "GotFocus" handler automatically, do this: drag your textbox to the form, and give it a name (in the designer). The default name will
be
TextBox1 for the first text box.

Go to the code view, and in the left-hand dropdown just above the code, select "TextBox1", or whatever you named it. Then in the righ-hand
dropdown, select the "GotFocus" item (it will have a little lightning bolt next to it). This will create the Shell of the event handler.

In the code I sent, it assumes that the text box was named TextBox1. If it
wasnt, change the part that says
... "Handles TextBox1.GotFocus "
To "Handles TheRealNameOfMyTextBox.GotFocus".

By named, I mean this : in the designer of your form, select the text box. Look in the properties window and find the "(name)" property.
Whatever
is entered there is the "name" of the text box that I keep referring to.


"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@sparta.btinternet.com...
> Thanks, I was going to ask for a pointer..... now I'm going to ask
for > another !
>
> I get this error...
>
> Handles clause requires a WithEvents variable
>
> Jane
>
> "Philip Rieck" <st***@mckraken.com> wrote in message
> news:eH**************@tk2msftngp13.phx.gbl...
> > While I probably wouldn't normally hardcode a string literal, this
should
> > give you the idea to get started.
> >
> > Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
> > System.EventArgs) Handles TextBox1.GotFocus
> > If TextBox1.Text = "Enter your name here" Then
> > TextBox1.Text = ""
> > End If
> > End Sub
> >
> > Or, to keep the default text there until they start typing:
> > Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
> > System.EventArgs) Handles TextBox1.GotFocus
> > If TextBox1.Text = "Enter your name here" Then
> > TextBox1.SelectAll()
> > End If
> > End Sub
> >
> >
> > "Jane Sharpe" <JS**@hotmail.com> wrote in message
> > news:bu**********@hercules.btinternet.com...
> > > Hi,
> > >
> > > I have a textbox with the words "Enter your name here" inserted as > default
> > > text - At the moment, to remove this the user must highlight all the > text
> > > and delete before they type in their name - I've seen sites

where all
> this
> > > text dissapears as soon as the user clicks on it - how do I do

that
?
> > >
> > > Thanks
> > >
> > > Jane
> > >
> > >
> >
> >
>
>



Nov 20 '05 #8
hum
you forgot to specify one little detail
it's a webapplication...

try this group: microsoft.public.dotnet.framework.aspnet


"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@titan.btinternet.com...
Thanks for all this help, but I just CANT get this all to gel.

With this test code, I get the error

BC30590: Event 'GotFocus' cannot be found.
Heres my test code:-

<%@ Page Language="VB" %>

<script runat="server">

Private WithEvents TextBox1 As TextBox
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "Enter your name here" Then
TextBox1.Text = ""
End If
End Sub

</script>

<html>

<body>
<form Id="frmForm1" runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server" BorderStyle="Solid"
Enter your name here</asp:TextBox> </p>
</form>
</body>
</html>

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:O2**************@TK2MSFTNGP10.phx.gbl...
when defining your textbox add withevents keyword:
private WithEvents myTextbox As TextBox
other solution:

private myTextbox As TextBox
Public Sub New()
addHandler myTextbox.GotFocus, AddressOf TextBox1_GotFocus
End Sub

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs)
...
End Sub
or something that looks alike ;-)

"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@titan.btinternet.com...
And there probably lies my problem, I'm not developing in studio, just
writing code !

"Philip Rieck" <st***@mckraken.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
> To create the "GotFocus" handler automatically, do this: drag your

textbox
> to the form, and give it a name (in the designer). The default name

will
be
> TextBox1 for the first text box.
>
> Go to the code view, and in the left-hand dropdown just above the code, > select "TextBox1", or whatever you named it. Then in the righ-hand
> dropdown, select the "GotFocus" item (it will have a little lightning
bolt
> next to it). This will create the Shell of the event handler.
>
> In the code I sent, it assumes that the text box was named TextBox1. If it
> wasnt, change the part that says
> ... "Handles TextBox1.GotFocus "
> To "Handles TheRealNameOfMyTextBox.GotFocus".
>
> By named, I mean this : in the designer of your form, select the
text
box.
> Look in the properties window and find the "(name)" property. Whatever
is
> entered there is the "name" of the text box that I keep referring

to. >
>
>
>
> "Jane Sharpe" <JS**@hotmail.com> wrote in message
> news:bu**********@sparta.btinternet.com...
> > Thanks, I was going to ask for a pointer..... now I'm going to ask

for > > another !
> >
> > I get this error...
> >
> > Handles clause requires a WithEvents variable
> >
> > Jane
> >
> > "Philip Rieck" <st***@mckraken.com> wrote in message
> > news:eH**************@tk2msftngp13.phx.gbl...
> > > While I probably wouldn't normally hardcode a string literal, this > should
> > > give you the idea to get started.
> > >
> > > Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
> > > System.EventArgs) Handles TextBox1.GotFocus
> > > If TextBox1.Text = "Enter your name here" Then
> > > TextBox1.Text = ""
> > > End If
> > > End Sub
> > >
> > > Or, to keep the default text there until they start typing:
> > > Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
> > > System.EventArgs) Handles TextBox1.GotFocus
> > > If TextBox1.Text = "Enter your name here" Then
> > > TextBox1.SelectAll()
> > > End If
> > > End Sub
> > >
> > >
> > > "Jane Sharpe" <JS**@hotmail.com> wrote in message
> > > news:bu**********@hercules.btinternet.com...
> > > > Hi,
> > > >
> > > > I have a textbox with the words "Enter your name here"
inserted as > > default
> > > > text - At the moment, to remove this the user must highlight
all the
> > text
> > > > and delete before they type in their name - I've seen sites

where all
> > this
> > > > text dissapears as soon as the user clicks on it - how do I do

that
?
> > > >
> > > > Thanks
> > > >
> > > > Jane
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #9
AhHa! it's a web application. That makes it a different beast:
The GotFocus event doesn't really make sense in a web application, since the
events in your VB.NET code are fired on the server side, not the client
side. To do this, you need to use some javascript.

Try this instead:

<%@ Page Language="VB" %>
<HTML>
<script runat="server">

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
TextBox1.Attributes.Add("onFocus", "removeText('" & TextBox1.ClientId &
"');")
End Sub

</script>

<script language=javascript>
function removeText( clientId)
{
document.getElementById( clientId).value = '';
}
</script>
<body>
<form Id="frmForm1" runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server" BorderStyle="Solid">
Enter your name here</asp:TextBox>
</p>
</form>
</body>
</HTML>


"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@titan.btinternet.com...
Thanks for all this help, but I just CANT get this all to gel.

With this test code, I get the error

BC30590: Event 'GotFocus' cannot be found.
Heres my test code:-

<%@ Page Language="VB" %>

<script runat="server">

Private WithEvents TextBox1 As TextBox
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "Enter your name here" Then
TextBox1.Text = ""
End If
End Sub

</script>

<html>

<body>
<form Id="frmForm1" runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server" BorderStyle="Solid"
Enter your name here</asp:TextBox> </p>
</form>
</body>
</html>

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:O2**************@TK2MSFTNGP10.phx.gbl...
when defining your textbox add withevents keyword:
private WithEvents myTextbox As TextBox
other solution:

private myTextbox As TextBox
Public Sub New()
addHandler myTextbox.GotFocus, AddressOf TextBox1_GotFocus
End Sub

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs)
...
End Sub
or something that looks alike ;-)

"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@titan.btinternet.com...
And there probably lies my problem, I'm not developing in studio, just
writing code !

"Philip Rieck" <st***@mckraken.com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
> To create the "GotFocus" handler automatically, do this: drag your

textbox
> to the form, and give it a name (in the designer). The default name

will
be
> TextBox1 for the first text box.
>
> Go to the code view, and in the left-hand dropdown just above the code, > select "TextBox1", or whatever you named it. Then in the righ-hand
> dropdown, select the "GotFocus" item (it will have a little lightning
bolt
> next to it). This will create the Shell of the event handler.
>
> In the code I sent, it assumes that the text box was named TextBox1. If it
> wasnt, change the part that says
> ... "Handles TextBox1.GotFocus "
> To "Handles TheRealNameOfMyTextBox.GotFocus".
>
> By named, I mean this : in the designer of your form, select the
text
box.
> Look in the properties window and find the "(name)" property. Whatever
is
> entered there is the "name" of the text box that I keep referring

to. >
>
>
>
> "Jane Sharpe" <JS**@hotmail.com> wrote in message
> news:bu**********@sparta.btinternet.com...
> > Thanks, I was going to ask for a pointer..... now I'm going to ask

for > > another !
> >
> > I get this error...
> >
> > Handles clause requires a WithEvents variable
> >
> > Jane
> >
> > "Philip Rieck" <st***@mckraken.com> wrote in message
> > news:eH**************@tk2msftngp13.phx.gbl...
> > > While I probably wouldn't normally hardcode a string literal, this > should
> > > give you the idea to get started.
> > >
> > > Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
> > > System.EventArgs) Handles TextBox1.GotFocus
> > > If TextBox1.Text = "Enter your name here" Then
> > > TextBox1.Text = ""
> > > End If
> > > End Sub
> > >
> > > Or, to keep the default text there until they start typing:
> > > Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
> > > System.EventArgs) Handles TextBox1.GotFocus
> > > If TextBox1.Text = "Enter your name here" Then
> > > TextBox1.SelectAll()
> > > End If
> > > End Sub
> > >
> > >
> > > "Jane Sharpe" <JS**@hotmail.com> wrote in message
> > > news:bu**********@hercules.btinternet.com...
> > > > Hi,
> > > >
> > > > I have a textbox with the words "Enter your name here"
inserted as > > default
> > > > text - At the moment, to remove this the user must highlight
all the
> > text
> > > > and delete before they type in their name - I've seen sites

where all
> > this
> > > > text dissapears as soon as the user clicks on it - how do I do

that
?
> > > >
> > > > Thanks
> > > >
> > > > Jane
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #10
Did I not mention that little detail, my apologies, its confusing enough
finding the right newsgroup !!

Anyway, I'm working now, so Thank You, Thank You, Thank You !!

Jane

"Philip Rieck" <st***@mckraken.com> wrote in message
news:ey**************@TK2MSFTNGP10.phx.gbl...
AhHa! it's a web application. That makes it a different beast:
The GotFocus event doesn't really make sense in a web application, since the events in your VB.NET code are fired on the server side, not the client
side. To do this, you need to use some javascript.

Try this instead:

<%@ Page Language="VB" %>
<HTML>
<script runat="server">

Private Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
TextBox1.Attributes.Add("onFocus", "removeText('" & TextBox1.ClientId &
"');")
End Sub

</script>

<script language=javascript>
function removeText( clientId)
{
document.getElementById( clientId).value = '';
}
</script>
<body>
<form Id="frmForm1" runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server" BorderStyle="Solid">
Enter your name here</asp:TextBox>
</p>
</form>
</body>
</HTML>


"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@titan.btinternet.com...
Thanks for all this help, but I just CANT get this all to gel.

With this test code, I get the error

BC30590: Event 'GotFocus' cannot be found.
Heres my test code:-

<%@ Page Language="VB" %>

<script runat="server">

Private WithEvents TextBox1 As TextBox
Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TextBox1.GotFocus
If TextBox1.Text = "Enter your name here" Then
TextBox1.Text = ""
End If
End Sub

</script>

<html>

<body>
<form Id="frmForm1" runat="server">
<p>
<asp:TextBox id="TextBox1" runat="server" BorderStyle="Solid"
Enter your name here</asp:TextBox>

</p>
</form>
</body>
</html>

"Dominique Vandensteen" <domi.vds_insert@tralala_tenforce.com> wrote in
message news:O2**************@TK2MSFTNGP10.phx.gbl...
when defining your textbox add withevents keyword:
private WithEvents myTextbox As TextBox
other solution:

private myTextbox As TextBox
Public Sub New()
addHandler myTextbox.GotFocus, AddressOf TextBox1_GotFocus
End Sub

Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As
System.EventArgs)
...
End Sub
or something that looks alike ;-)

"Jane Sharpe" <JS**@hotmail.com> wrote in message
news:bu**********@titan.btinternet.com...
> And there probably lies my problem, I'm not developing in studio, just > writing code !
>
> "Philip Rieck" <st***@mckraken.com> wrote in message
> news:uj**************@TK2MSFTNGP12.phx.gbl...
> > To create the "GotFocus" handler automatically, do this: drag your
textbox
> > to the form, and give it a name (in the designer). The default name will
> be
> > TextBox1 for the first text box.
> >
> > Go to the code view, and in the left-hand dropdown just above the

code,
> > select "TextBox1", or whatever you named it. Then in the righ-hand > > dropdown, select the "GotFocus" item (it will have a little lightning bolt
> > next to it). This will create the Shell of the event handler.
> >
> > In the code I sent, it assumes that the text box was named TextBox1.
If
> it
> > wasnt, change the part that says
> > ... "Handles TextBox1.GotFocus "
> > To "Handles TheRealNameOfMyTextBox.GotFocus".
> >
> > By named, I mean this : in the designer of your form, select the text box.
> > Look in the properties window and find the "(name)" property.

Whatever
is
> > entered there is the "name" of the text box that I keep referring to. > >
> >
> >
> >
> > "Jane Sharpe" <JS**@hotmail.com> wrote in message
> > news:bu**********@sparta.btinternet.com...
> > > Thanks, I was going to ask for a pointer..... now I'm going to
ask
for
> > > another !
> > >
> > > I get this error...
> > >
> > > Handles clause requires a WithEvents variable
> > >
> > > Jane
> > >
> > > "Philip Rieck" <st***@mckraken.com> wrote in message
> > > news:eH**************@tk2msftngp13.phx.gbl...
> > > > While I probably wouldn't normally hardcode a string literal,

this > > should
> > > > give you the idea to get started.
> > > >
> > > > Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e
As > > > > System.EventArgs) Handles TextBox1.GotFocus
> > > > If TextBox1.Text = "Enter your name here" Then
> > > > TextBox1.Text = ""
> > > > End If
> > > > End Sub
> > > >
> > > > Or, to keep the default text there until they start typing:
> > > > Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As > > > > System.EventArgs) Handles TextBox1.GotFocus
> > > > If TextBox1.Text = "Enter your name here" Then
> > > > TextBox1.SelectAll()
> > > > End If
> > > > End Sub
> > > >
> > > >
> > > > "Jane Sharpe" <JS**@hotmail.com> wrote in message
> > > > news:bu**********@hercules.btinternet.com...
> > > > > Hi,
> > > > >
> > > > > I have a textbox with the words "Enter your name here"

inserted
as
> > > default
> > > > > text - At the moment, to remove this the user must highlight

all the
> > > text
> > > > > and delete before they type in their name - I've seen sites

where
> all
> > > this
> > > > > text dissapears as soon as the user clicks on it - how do I do that
> ?
> > > > >
> > > > > Thanks
> > > > >
> > > > > Jane
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: msnews.microsoft.com | last post by:
Hello! I'm Jim by asp How can show "abc" in textbox when click one botton?
1
by: Danial | last post by:
Hi, I am using asp.net 2 and i want to blank all textbox data of one form with (for each control) and i write following coding in button control, but it did not work. Dim ctl As Control ...
17
by: lokidog | last post by:
I am trying to automatically transfer data from one textbox to another between subforms within a 'main' form. I put this code into the Gotfocus eventprocedure: Private Sub Date_GotFocus() If...
0
by: KCLA | last post by:
HELLO AND THANKS IN ADVANCE I am new to programming although my best mate is quite good and i have learnt a lot from him but i am now trying to understand the basic concept, however i cannot find...
3
by: HockeyFan | last post by:
I've done this before by trapping keydown and checking for a CR, and then clicking a particular button based on which textbox the event happened. However, I was wondering if there's a simpler way...
1
by: =?Utf-8?B?dmJTdHVkZW50?= | last post by:
Dear All, I have textbox in my form .. I enter the student name in the text e.x (vbstudent) I want to sign textbox data to array, each letter in one index. ex array(0)=v array(1)=b
5
by: hidayu1986 | last post by:
how to disable textbox when click on radiobutton using VB script on Visual Studio.Net 2005. currently i used this coding but it is not functioning. Private sub...
15
by: Martin Lang | last post by:
Hi All, Thanks for reading this :) I have a form A that consists of a main form A and a sub form A. In sub form A, I have a field which I can double click. Then, Main form B opens up with a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.