Solved

ASP Textbox and onclick

Posted on 2009-05-14
11
1,508 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 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