?
Solved

Copy value from one textbox to another textbox

Posted on 2009-05-06
6
Medium Priority
?
786 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
Technology Partners: 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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

765 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