tags:

views:

26

answers:

2

i have a TextBox control on my masterpage

<asp:TextBox ID="txtSubject" runat="server" Width="280px" CssClass="formtxt"
onblur="if(this.value=='') this.value='Enter text,150 characters only';" 
onfocus="if(this.value == 'Enter text,150 characters only') this.value='';" 
Text="Enter text,150 characters only"  CausesValidation="false"></asp:TextBox>  

the problem is that, i dont want the textbox to have a setfocus due to the watermark on the textbox; if i have a setfocus on the textbox the watermark is now showing.

A: 

Have a look at Form.DefaultFocus- setting to empty string might help.

RichardOD
this.form1.DefaultFocus = ""; focus is not there but i dont see the watermark text its empty.
Abu Hamzah
i accept the answer as i have asked how NOT to setfocus
Abu Hamzah
A: 

Your code works for me, but this might depend on some settings not shown in your sample (e.g. DefaultFocus attribute of the Form element) or the browser being used.

As an alternative, you could use the onkeydown event instead of onfocus:

<asp:TextBox ID="txtSubject" ...
  onblur="if(this.value=='') this.value='Enter text,150 characters only';"
  onkeydown="if(this.value == 'Enter text,150 characters only') this.value='';" ...>
</asp:TextBox>

Update: I was able to reproduce the behavior you described, when I set <form DefaultFocus="txtSubject">

M4N
Yes I also concur that the code works for me too!
RichardOD
does not work with onkeydown same behaviour as described above.
Abu Hamzah