3
Answers

add data in textbox

 i  have one textbox  and one button
 
<asp:TextBox ID="txtPrevPol" runat="server" Placeholder="Policy No" class="form-control" ValidationGroup="P" />
 
<asp:Button ID="btnPAdd" runat="server" Text="Add" class="form-control btn btn-primary" ValidationGroup="P" />
 
 
i put value first in this textbox (ex: 1234)
 
it added and show in another textbox
 
<asp:TextBox ID="txtPrevPolList" runat="server"  TextMode="MultiLine" ReadOnly="true" ></asp:TextBox>
 
output like that:
 
(ex:
1. 1234)
 
 
again i added the valur in the textbox ( txtPrevPol)( ex :3456)
 
 
show it in the txtPrevPolList
output:
 
(ex:
1. 1234
2. 3456 ) 
 
i am doing this using the following script:
 
<script>
var cnf = $.noConflict();
var count = 1;
cnf('#<%=btnPAdd.ClientID%>').click(function () {
var txt = cnf('#<%=txtPrevPol.ClientID%>').val();
if (txt != '') {
cnf('#<%=txtPrevPolList.ClientID%>').append((count++) + ':' + txt + '\n');
cnf('#<%=txtPrevPol.ClientID%>').val('');
return false;
}

});
 
 
when i fetch  all values from the textbox (
txtPrevPolList
(ex:
1. 1234
2. 3456 ) )
 
  to save it into the database
 
 
 i cannot get the values from the textbox 
 

Answers (3)

0
Photo of Midhun T P
NA 19.7k 281.2k 7y
Hi,
 
You can't get the value of textbox in backend if updated by script. I would suggest you to keep a hidden field and update the value to that hidden field also. Then you can take value of  that hidden field in backend.
 
  1. <asp:HiddenField ID="hdnpollist" runat="server" />  
  1. var cnf = $.noConflict();  
  2.             var count = 1;  
  3.             cnf('#<%=btnPAdd.ClientID%>').click(function () {  
  4.                 var txt = cnf('#<%=txtPrevPol.ClientID%>').val();  
  5.                 if (txt != '') {  
  6.                     cnf('#<%=txtPrevPolList.ClientID%>').append((count++) + ':' + txt + '\n');  
  7.                     cnf('#<%=hdnpollist.ClientID%>').val(cnf('#<%=txtPrevPolList.ClientID%>').val());  
  8.                     cnf('#<%=txtPrevPol.ClientID%>').val('');  
  9.                     return false;  
  10.                 }  
  11. });  
  1. string value = hdnpollist.Value;  
Accepted
0
Photo of Midhun T P
NA 19.7k 281.2k 7y
Hi,
 
If you need only values, then you can make small change in script as below -
 
  1. var cnf = $.noConflict();  
  2.             var count = 1;  
  3.             cnf('#<%=btnPAdd.ClientID%>').click(function () {  
  4.                 var txt = cnf('#<%=txtPrevPol.ClientID%>').val();  
  5.                 if (txt != '') {  
  6.                     cnf('#<%=txtPrevPolList.ClientID%>').append((count++) + ':' + txt + '\n');  
  7.                     cnf('#<%=hdnpollist.ClientID%>').val(cnf('#<%=hdnpollist.ClientID%>').val() + txt + ',');  
  8.                     cnf('#<%=txtPrevPol.ClientID%>').val('');  
  9.                     return false;  
  10.                 }  
  11.  });  
 
0
Photo of aiswarjya sarengi
NA 271 9.2k 7y
Now i get a result
 
1,1232,4563,7894,102
 
but i  want to replace   it  like the following
( replace 1,2,3,4,............)
 
123,456,789,102