Solved

ASP Textbox and onclick

Posted on 2009-05-14
11
1,452 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

785 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