views:

293

answers:

3

Hi all,

I'm trying to watermark the asp:Login controls' Username and Password fields with jQuery, I've tried various ways of referencing the control ID:

$('#<%=ClientID.Login1_UserName %>').watermark('watermark', 'Username');

I have tried moving the ClientID, Login1 and UserName around and changing the selectors to and from userscores and periods...

Any ideas?

+3  A: 

Good old jQuery selectors ;)

$("input[name*='UserName']").watermark('watermark', 'Username');
Gogster
A: 
$("input[id$='_UserName']:first").watermark('watermark', 'Username');
Doc Hoffiday
A: 

If you have an

<asp:TextBox ID="Login1_UserName" ... >

then your jquery code needs to look something like this

<script type="text/javascript">
<!--
    $(document).ready(function() {
        $('#<%= Login1_UserName.ClientID %>').watermark('watermark', 'Username');
    }
// -->
</script>

although @Gogster had a very good suggestion as well--to avoid the <% %> tags altogether, which in my opinion is a bit more elegant and no less difficult to understand.

Kimball Robinson
I agree k.robinson, although I am agreeing with myself and you!) also the code tags cause problems with validation.
Gogster