Solved

ASP Textbox and onclick

Posted on 2009-05-14
11
1,463 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
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

791 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