Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1571
  • Last Modified:

ASP Textbox and onclick

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
mwhodges
Asked:
mwhodges
1 Solution
 
silemoneCommented:
where are you getting the warning?  like as in a javascript page error?
0
 
AanvikCommented:
Why do you need Click event on text box control, try GotFocus Event and it should do the same for you.
0
 
wellholeCommented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
mwhodgesAuthor Commented:
I am getting the error at compilation. I couldnt find a gotfocus as one of my choices in asp.
0
 
mwhodgesAuthor Commented:
Do I put that code directly into my vb script page load event or into the html side?
0
 
silemoneCommented:
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
 
silemoneCommented:
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
 
channa_mCommented:
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
 
mwhodgesAuthor Commented:
Where exactly does this go?
ctrl.Attributes.Add("onClick", "code")
0
 
silemoneCommented:
that goes in the page load on the server side code...
0
 
silemoneCommented:
more specifically inside of the  if Not Page.isPostback block if you have one...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now