Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
how can i maintain the textbox value when the page is post back ..i am getting value in textbox using java script..
Posted
Comments
Ankur\m/ 18-Dec-10 6:17am    
Can you give the following code:
1) JavaScript code that you are using to set the value.
2) How are you using the code.

You can maintain textbox value using viewstate, when the page is post back.
 
Share this answer
 
Comments
Sandeep Mewara 18-Dec-10 5:55am    
Comment from OP:
ya i have taken enableviewstate as true ..but it is still not maintaining the data..
Ankur\m/ 18-Dec-10 6:18am    
ViewState has nothing to do here. The text property of a textbox is maintained by its control state. So even if you disable the ViewState the text will still persist.
This works for me:

XML
<script type="text/javascript">
        function setValue()
        {
            document.getElementById("TextBox1").value = "abcd";
            return true;
        }
</script>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return setValue();" onclick="Button1_Click" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900