Solved

ASP Textbox and onclick

Posted on 2009-05-14
11
1,486 Views
Last Modified: 2012-06-22
I am using asp.net and I have a text box that uses the onclick command to change the value of the box.  I get a warning that onclick is not a valid attribute of element 'Textbox' but it works. Is there any concern for this warning and best yet how can I get rid of it?

Thanks in advance
0
Comment
Question by:mwhodges
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 21

Expert Comment

by:silemone
ID: 24385819
where are you getting the warning?  like as in a javascript page error?
0
 
LVL 5

Expert Comment

by:Aanvik
ID: 24385824
Why do you need Click event on text box control, try GotFocus Event and it should do the same for you.
0
 
LVL 9

Accepted Solution

by:
wellhole earned 250 total points
ID: 24385906
onclick is not actually a valid attribute for the asp Textbox. However, the result is that asp will add this attribute to your html tag anyway. To avoid this issue, you can add this attribute to your control during the page loading event.

ctrl.Attributes.Add("onClick", "code")
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mwhodges
ID: 24385922
I am getting the error at compilation. I couldnt find a gotfocus as one of my choices in asp.
0
 

Author Comment

by:mwhodges
ID: 24385934
Do I put that code directly into my vb script page load event or into the html side?
0
 
LVL 21

Expert Comment

by:silemone
ID: 24385996
well can you use label instead...it has an onclick event...then on click, do what you want it to do and change it to a text box for text entry...
this would would mean you would put this section in an UpdatePanel which will let the page partially postback and switch between label and textbox...textbox doesn't have an onclick event...onchange....
0
 
LVL 21

Expert Comment

by:silemone
ID: 24386031
another way to do this is to use the onkeypress event...you can test key press to the keycode of the enter button and then continue from there...
0
 
LVL 3

Expert Comment

by:channa_m
ID: 24386198
onClick is a javascript event and is not part of .net server control, it sill works because ultimate the asp.net is rendered as an html.
0
 

Author Comment

by:mwhodges
ID: 24386221
Where exactly does this go?
ctrl.Attributes.Add("onClick", "code")
0
 
LVL 21

Expert Comment

by:silemone
ID: 24387859
that goes in the page load on the server side code...
0
 
LVL 21

Expert Comment

by:silemone
ID: 24387985
more specifically inside of the  if Not Page.isPostback block if you have one...
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question