Solved

Copy value from one textbox to another textbox

Posted on 2009-05-06
6
778 Views
Last Modified: 2012-05-06
Hello Guys! I am stuck in a situation where in i need to copy txtbox1's value into txtbox2. I am able to accomplish this using the following code, which is in the page_load event

        txtbox1.Attributes.Add("onblur", String.Format("javascript:document.getElementById('{0}').value=document.getElementById('{1}').value;", txtbox2.ClientID, txtbox1.ClientID))

Everything seems to work perfectly, but to prevent the user from editing the text i have disabled txtbox2. So now what happens is when txtbox2 receives the focus, it gets the value from txtbox1. The problem arises when we go to the next control which is got postback enabled, and when the post back occurs, the value in txtbox2 disappears.

How do I retain the value in the text box. My main aim is that the user should not be able to edit the text in txtbox2.



example.JPG
0
Comment
Question by:preethamonline
6 Comments
 
LVL 33

Expert Comment

by:jppinto
ID: 24312699
0
 
LVL 9

Accepted Solution

by:
RobertNZana earned 500 total points
ID: 24312773
You cant just use Ajax and do something like...

txtCTC.text = txtAllowance.text

Do it on the txtAllowance.text event and enable autopostback.
0
 
LVL 4

Expert Comment

by:cauos
ID: 24312785
you can check the value of the textbox in the page load if is it empty and the second textbox is not empty then assign the value of the first textbox to the second textbox like in the snippet code
<body onload="doChange()">
function doChange()

{

    if (document.getElementById("TextBox1").value =" " && document.getElementById("TextBox2").value !="")

        document.getElementById("TextBox1").value = document.getElementById("TextBox2").value

}

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:DreamsTech
ID: 24312870
its happening as the changes made by script on a text box which is disabled are lost during the Postback,means if you populated any value by means of script without manually writing ,these value will be lost during the PostBack.Its a perfect ok and no mistake from ur end.

The work around is ,make a thumb rule that any changes u do in script ,re write the same the same logic in Pre Render Event. In your case ,Populate a Hidden Html Input with the values you populated in your disable TextBox ,and in Prerender load the value from the Html Hidden Input back to your disables textbox
0
 

Author Comment

by:preethamonline
ID: 24313173
Thanks guys for your help. Will try it out and let you know.
0
 

Author Closing Comment

by:preethamonline
ID: 31578370
Thank you all. This was the most effective and simple soluton i felt.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now