• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 699
  • Last Modified:

ASP.NET/Javascript - TextArea deletes data on Postback...

I have a textarea on my vb.net page...but when the page autopostabacks...the data in the textarea is gone...is there a way to keep this data...the user gets frustrated that all their data is gone..and they have to retype...Jsession varable javascript anwser?
0
GlobaLevel
Asked:
GlobaLevel
  • 4
  • 2
  • 2
  • +2
1 Solution
 
ajayvegesna02Commented:
use Viewstate for retaining the data on postbacks
0
 
ajayvegesna02Commented:
set the attribute EnableViewState=true. i hope this will be enough...
0
 
radcaesarCommented:
Textarea is HTML Control and viewstate will not be applicable. You need to get/set the value manually

Like, document.getElementById('<%=TextArea1.ClientID%>').value

http://forums.asp.net/p/1632813/4209700.aspx

A Sample in PHP

<textarea cols="50" rows="5" name="descr"><?php echo $_POST['descr'];?></textarea>
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
GlobaLevelAuthor Commented:
thanks all..but Im using asp.net...anyone else...actual code?
0
 
GlobaLevelAuthor Commented:
okay so the hiddenfield is not quite working here....


window.onload = function () {
 
        
       // sessionDuration = document.getElementById("<%= sessionDuration.ClientID %>").value;
         document.getElementById("<%= txtTextbox2.ClientID %>").innerHTML = document.getElementById("<%= attendant_name.ClientID %>").value 
         document.getElementById("<%= textarea2.ClientID %>").innerHTML = document.getElementById("<%= attendant_name1.ClientID %>").value 

         document.getElementById("<%= textarea3.ClientID %>").innerHTML = document.getElementById("<%= attendant_name2.ClientID %>").value 

         document.getElementById("<%= textarea4.ClientID %>").innerHTML = document.getElementById("<%= attendant_name3.ClientID %>").value 

         document.getElementById("<%= textarea5.ClientID %>").innerHTML = document.getElementById("<%= attendant_name4.ClientID %>").value 

     
    }

Open in new window

0
 
GlobaLevelAuthor Commented:
its saying these controls are not declared...
0
 
dejaanbuCommented:
>>document.getElementById("<%= attendant_name.ClientID %>").value  -

if this is a client side normal html hidden field u can directly access it by

document.getElementById('attendant_name').value  

those <%= %> are needed only for server controls
0
 
Manoj PatilSr. Software EngineerCommented:
You just try with

if (!IsPostBack)
{ 
        String example = textbox1.Text;

}

Open in new window

0
 
GlobaLevelAuthor Commented:
so this will work to retain the user data on form refresh in Text area:

if is postback then
<%textarea1.clientid%>.value = document.getElementById('attendant_name').value  


end if
0
 
dejaanbuCommented:
u can try the following also:

in ur button click server event , you can store the textarea value in session or viewstate

something like

session("TheVariable")=textarea1.text

Open in new window



and then if the session/viewstate value is set, then you assign the value to the text area in page load event..


if is page.postback then
textarea1.text = iif(string.isNullorEmpty(Session("TheVariable"),"",Session("TheVariable"))
End if

Open in new window


not sure about ur requirement...but give it a try
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now