Click here to Skip to main content
15,878,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all...
i am developing a asp.net application using C#..
i want the value of the text box should be filled automatically according to the value of another text box........

Please Help........
Posted

I would suggest you to give some time to learn and understand the basics.

i want the value of the text box should be filled automatically according to the value of another text box........

The simplest option is to enable AutoPostBack of the TextBox and handle it's TextChanged event.

The code will be something like:

XML
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" ontextchanged="TextBox1_TextChanged"></asp:TextBox>


And in the code behind, it will be like:
C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
    //assign value to another text box here.
}


This method is recommended if you need some database interaction or compulsory server side processing.
If the values can be processed on the client side, I recommend using JavaScript to do the same because this avoids a page post back.

The method I suggested above can also be done using AJAX.

Hope this helps!
 
Share this answer
 
v2
Comments
Dipesh Gupta 28-Feb-11 14:09pm    
thanx for ur help.......
Ankur\m/ 28-Feb-11 23:30pm    
You are welcome. Do work on the suggestion given to you in the very first line.

And you may also accept the answer if it answers your question well.
Cheers!
Ankur
I would like to suggest you use javascript for this
Collapse
<asp:textbox id="TextBox1" runat="server" >
<asp:textbox id="TextBox2" runat="server" >


and now on page_load write the line below
TextBox1.Attributes.Add("onblur","ManipulateValue(this)")

and then handle it in javascript

<script language="javascript">
function ManipulateValue(txt)
{
var text2=document.getElementById("<%=TextBox2.ClientID %>");
text2.value=txt.value;
}
</script>

here i assign the value of textbox1 to 2 but you can perform some task on that.

This will avoid postback which will be happen on server side code..

--Pankaj
 
Share this answer
 
v3
Comments
Sreejith Gopinathan 28-Feb-11 6:24am    
+5 :) but onblur instead of onclick
pankajupadhyay29 28-Feb-11 6:35am    
thanks for quick correction i missed that.
Dipesh Gupta 28-Feb-11 14:08pm    
thanx........
Abhinav S 28-Feb-11 23:17pm    
You are welcome. Vote if it helped. :)
See this very simple example[^] - it will surely help you out.
 
Share this answer
 
Comments
Dipesh Gupta 28-Feb-11 14:09pm    
thankx........

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900