Tasawer Khan
Tasawer Khan

Reputation: 6148

What is the problem with this onload event?

I have this password field

input class="txtfld" type="password" id="TextBoxLoginPassword"  runat="server" 
                value="password"     
                onfocus="javascript:if(this.value == 'password') this.value='';" 
                onblur="javascript:if(this.value == '') this.value='password';" 
                onload="javascript:if(this.value == '') this.value='password';"
                validationgroup="Login" />

Problem is that this appears as empty. Even I have set a default value. To solve this problem I have added an onload event and I get following error

  1. Empty Character Literal
  2. Too many Characters in character literals Why does this appear empty in first place and why do I get these errors? What I need is to show a default value in password field.

Upvotes: 1

Views: 1262

Answers (4)

Hans Kesting
Hans Kesting

Reputation: 39329

The problem is in the combination of the text in the OnLoad and the runat=server.

Because of that runat attribute, asp.net thinks the OnLoad specifies a server-side function. And then '' and 'password' seem (at least to C#) to specify character literals, of which the first has too few actual characters ("Empty Character Literal") and the second too many.

So try to remove the "runat=server" (and read the password directly from the QueryString)

Upvotes: 2

Daniel Dyson
Daniel Dyson

Reputation: 13230

Here is a really sweet bit of JQuery / CSS that you could use here and elsewhere in your site to solve your problem:

http://attardi.org/labels/#demo

Upvotes: 1

Adeel
Adeel

Reputation: 19228

@Hans Kesting answer is correct, but if you don't want to use extender, you can use the following code.

<input class="txtfld" type="text" id="TextBoxLoginPassword"   
                value="enter password"     
                onfocus="javascript:if(this.type != 'password') this.value='';this.type='password'" 
                 />

Upvotes: 1

Hans Kesting
Hans Kesting

Reputation: 39329

It seems to me that you want to provide a "watermark", not the real password. Have you looked at the Watermark extender of the Ajax control toolkit?

Upvotes: 2

Related Questions