Link to home
Start Free TrialLog in
Avatar of GlobaLevel
GlobaLevelFlag for United States of America

asked on

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?
Avatar of ajayvegesna02
ajayvegesna02

use Viewstate for retaining the data on postbacks
set the attribute EnableViewState=true. i hope this will be enough...
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>
Avatar of GlobaLevel

ASKER

thanks all..but Im using asp.net...anyone else...actual code?
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

its saying these controls are not declared...
Avatar of Deja Anbu
>>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
You just try with

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

}

Open in new window

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
ASKER CERTIFIED SOLUTION
Avatar of Deja Anbu
Deja Anbu
Flag of Oman image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial