Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Copy value from one textbox to another textbox

Posted on 2009-05-06
6
Medium Priority
?
787 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 33

Expert Comment

by:jppinto
ID: 24312699
0
 
LVL 9

Accepted Solution

by:
RobertNZana earned 2000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

604 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