Click here to Skip to main content
11,416,531 members (61,347 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: jQuery
I am using following code to set the value of textbox in asp.net using JQuery. But still its not setting the value.

$('<%=txtSStreet.ClientID %>').val("Street");
$('<%=txtSState.ClientID %>').val("City");
$('<%=txtSDistrict.ClientID %>').val("State");
// $('<%=ddlSCountry.ClientID %>').attr("value","Country");
$('<%=txtSZipcode.ClientID %>').val("ZIPCode");
$('<%=txtSPostalAddress.ClientID %>').val("PostalAddress");
Posted 3-Oct-10 23:30pm
Edited 19-Oct-11 4:40am
v2
Comments
kiran dangar at 19-Oct-11 9:41am
   
Have you placed your code inside $(document).ready() ??
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

You can try this way..

$(document).ready(function()
    {
        $('#<%=txtSStreet.ClientID %>').val("Street");
        $('#<%=txtSState.ClientID %>').val("City");
        $('#<%=txtSDistrict.ClientID %>').val("State");
        // $('#<%=ddlSCountry.ClientID %>').attr("value","Country");
        $('#<%=txtSZipcode.ClientID %>').val("ZIPCode");
        $('#<%=txtSPostalAddress.ClientID %>').val("PostalAddress");
    });


Hope this will help...

[Please click on "Accept Answer" if this helps you]
  Permalink  
v3
Comments
JQuery Geeks at 24-Oct-11 1:37am
   
right way
preet88 at 23-May-12 7:13am
   
how we can access all text boxes can you tell me??
for eg $(.textbox) refers to class of textbox
similarly if i want to refer all textboxes how to do that???
Killzone DeathMan at 23-Nov-12 4:49am
   
I thing its the same way, just add the class="textbox" and in jquery $('.textbox').val('My Text');
Am I right?
deepak.m.shrma at 5-Nov-12 22:41pm
   
@preet
$("input[type*='text']") gives you array of text, using 'each' method u can manipulate all textboxes.
ex.
$("input[type*='text']").each(function(count){
$(this).val('count = '+count);
});
Sampath Sridhar at 10-Mar-13 23:39pm
   
The answer is correct.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 12

Instead of

$('<%=txtSStreet.ClientID %>').val("Street");

try this :

$('#' +'<%=txtSStreet.ClientID %>').val("Street");

Thanks,
Jyotish
  Permalink  
Comments
Member 11031891 at 23-Aug-14 22:13pm
   
This is the correct solution since, in the question, those are IDs you are trying to set. The # indicates an ID, so this must prepend the <%=xxxxxxxx.ClientID %>.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 11

$(‘:submit’).click(function () {
$(‘div’).text(‘This is new text.’) ;

This will set the Text value of 'div' element on submit button click.
You can similarly set the textbox value, replace 'div' with '#textbox_id'

Regards,
Abhisheik
  Permalink  
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 15

Put $(document).ready function on the top OR u can put $(function(){}); and into the curly braces u can write down your code. Your problem will be resolved.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 14

set txtSStreet textbox's clientidmode property to static in aspx page then using jquery
$('#txtSStreet').val('value you want to set');
  Permalink  
Comments
GeraldTrost at 16-Nov-14 0:30am
   
THIS is the right answer!
other answers came from people who don't deal with ASP.NET
and so they dont have experienced this issue!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

hey buddy . u can use below code to find textbox and set its value.

$('#ControlName').val('value');


Please Vote for Answer
  Permalink  
Comments
Shining Legend at 4-Oct-10 5:05am
   
I already tried this way but it is not working.
Sandip.Nascar at 22-Aug-12 13:56pm
   
This is a server side control. So, definitely this will not work.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

refer an example:

<head runat="server">
    <title></title>
    <script src="scripts/jquery.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        $(document).ready(function() {
            $('#btn1').click(function() {
                $('#Abc').val('Clicked')
                return false;
            });
            $('#btn2').click(function() {
                $('#Abc').val('Hit')
                return false;
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <input name="Abc" id="Abc" runat="server" />
     <input type="button" runat="server" value="click" id="btn1" />
     <asp:Button ID="btn2" runat="server" Text="Hit" />
    </div>
    </form>
</body>
  Permalink  
Comments
Saiseva at 22-Jun-11 16:24pm
   
Your code-example is very simple and easy.

This is ami, I am new in JQERY world.

I am learning and I show so many examples, tuorial etc. online.....But all are almost same start with $(document).ready()...WITHOUT IN-DEPT EXPLANATION OF $ and how to use basic syntax...i feeel sometime it is confusing...

More...Mostly Javascript codes are more to do with form's element like getting values..data validations...data manipulation..Less on CSS-HTML

Most of tutorial talks about CSS Element manipulation....Less on HTML ELEMENT DATA-VALUE Manipulation.

Do u have/know any tutorials/LINK/BOOK.......that clears begginners on HTML element side

For example : How to get value of text box, how to compare value of two password control, How to get date value, How do i know which radio button is selected, change text based on selected radio button...

Or tutorial tells..major functions used in data manipulation...

see if i see u r example i got what val function does.....but I can't just go by each function and read sytax...It doesn't provide any dudeligence..

Please let me know if anyone know..Better tutorial/link/book.

my id is ami_sur@yahoo.com

thanks
Ajith K Gatty at 7-Apr-14 8:17am
   
Try this link http://try.jquery.com

You can also read Javascript and Jquery, The missing manual 2nd edition.

Good Luck
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

put it in a $(document).ready
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 10

Use this...
$('#ControlName').val('value');
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,295
1 OriginalGriff 7,592
2 Maciej Los 3,718
3 Abhinav S 3,456
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web01 | 2.8.150427.4 | Last Updated 4 Dec 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100