Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP Textbox and onclick

Posted on 2009-05-14
11
Medium Priority
?
1,523 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 750 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

721 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