473,800 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
10 9052
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******** ******@TK2MSFTN GP10.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.EventArg s) Handles MyBase.PreRende r
TextBox1.Attrib utes.Add("onFoc us", "removeText ('" & TextBox1.Client Id &
"');")
End Sub

</script>

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


"Jane Sharpe" <JS**@hotmail.c om> wrote in message
news:bu******** **@titan.btinte rnet.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_GotFoc us(ByVal sender As Object, ByVal e As
System.EventArg s) Handles TextBox1.GotFoc us
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="So lid"
Enter your name here</asp:TextBox>

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

"Dominique Vandensteen" <domi.vds_inser t@tralala_tenfo rce.com> wrote in
message news:O2******** ******@TK2MSFTN GP10.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.GotFo cus, AddressOf TextBox1_GotFoc us
End Sub

Private Sub TextBox1_GotFoc us(ByVal sender As Object, ByVal e As
System.EventArg s)
...
End Sub
or something that looks alike ;-)

"Jane Sharpe" <JS**@hotmail.c om> wrote in message
news:bu******** **@titan.btinte rnet.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******** ******@TK2MSFTN GP12.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.GotFoc us "
> > To "Handles TheRealNameOfMy TextBox.GotFocu s".
> >
> > 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.c om> wrote in message
> > news:bu******** **@sparta.btint ernet.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******** ******@tk2msftn gp13.phx.gbl...
> > > > While I probably wouldn't normally hardcode a string literal,

this > > should
> > > > give you the idea to get started.
> > > >
> > > > Private Sub TextBox1_GotFoc us(ByVal sender As Object, ByVal e
As > > > > System.EventArg s) Handles TextBox1.GotFoc us
> > > > 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_GotFoc us(ByVal sender As Object, ByVal e As > > > > System.EventArg s) Handles TextBox1.GotFoc us
> > > > If TextBox1.Text = "Enter your name here" Then
> > > > TextBox1.Select All()
> > > > End If
> > > > End Sub
> > > >
> > > >
> > > > "Jane Sharpe" <JS**@hotmail.c om> wrote in message
> > > > news:bu******** **@hercules.bti nternet.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
3619
by: msnews.microsoft.com | last post by:
Hello! I'm Jim by asp How can show "abc" in textbox when click one botton?
1
1707
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 For Each ctl In Me.Controls
17
2618
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 Len(Trim$(Me!.Value & "")) = 0 Then 'This checks for blank or space-filled date field - it will only transfer data if it has not already been entered. Me! = !!.!.! SendKeys "{F2}" SendKeys "{TAB}"
0
869
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 anywhere yet that describes in laymens terms the process for building a programme, i am fine with layouts and such like but it is the basic starting procedure that i need to understand fully, has anyone got a flow chart or similar that shows the...
3
4552
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 to trap a carriage return in a textbox, and have it click a button?
1
6529
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
9084
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 RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged If RadioButton1.Checked Then Me.textBox1.Visible = True Else
15
11868
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 search field. Sub form B has a query as recordset. The query use the search field value as a filter, and the filter is updated every time text is entered into the search field. What I want to happen is to set focus on the search field once form b...
0
10505
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2945
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.