asp.net - jQuery Syntax for accessing asp:textbox -


i'm trying change value of asp:textbox using jquery using line of code i've found referenced in several places:

$("#<%= element.clientid %>").attr('value', ""); 

however, keep getting syntax error saying first part invalid expression. i'm sure it's simple i'm missing here, don't know is.

jquery linked via master page , .js file function containing line in question individually linked on specific page.

your syntax correct:

$('#<%= textbox.clientid%>').val('new textbox value'); 

is correct syntax selecting <asp:textbox /> via javascript , in case jquery; however, works in .aspx files.

you need convert separate .js file in-line script in .aspx page work.

alternatively, use css class selector, work external .js file:

in .js file

$('.uniquecssclassname').val('new textbox value'); 

in .aspx file

<asp:textbox id="whatever" cssclass="uniquecssclassname" /> 

this allow select text box external javascript file. not pretty approach, work. go first option, , move .js code inline script.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -