Solved

Copy value from one textbox to another textbox

Posted on 2009-05-06
6
779 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Paging GridView 7 48
Editing XSL files, 2 40
C# GridRow get Old/New Value 1 55
Remove greater than sign 3 42
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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

930 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