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


Jquery in an attribute?

Posted on 2011-09-16
Medium Priority
Last Modified: 2012-06-27
Why doesnt this work?

txtTimeBox1.Attributes.Add("onload", "$('" + txtTimeBox1.ID + "').text('Hi')");

I dont necessarily need for the textbox to say hi.  What Im trying to do is add jquery dynamically to a server control

Thanks Experts!
Question by:jdn717
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
  • 2
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36547742
try this

txtTimeBox1.onload = function(){
  this.val( "Hi" );

But i don't think that a input box can have onload event, so also try


also you can simple have the value in the textbox
<input type="text" value="Hi">
LVL 17

Expert Comment

ID: 36548005
When using ID selector you need # for selector
Try this

txtTimeBox1.Attributes.Add("onload", "$('#" + txtTimeBox1.ID + "').text('Hi')");
LVL 17

Accepted Solution

sonawanekiran earned 1497 total points
ID: 36548018

txtTimeBox1.Attributes.Add("onload", "$('#" + txtTimeBox1.ClientID + "').text('Hi')");

Author Closing Comment

ID: 36562013
The answer was correct, not necessrly what i was lookng for.  Mainly because of my failure to describe it better

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

722 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