Call to ClientScript doesnot preserve value in Controls of Web Page

menace

New Member
If page is refreshed using F5 , TextBox should preserve its old value . In Page_Load() , if i keep comment , TextBox1 preserve its old value.
As soon as i remove comment , it loose value in TextBox1 .Please tell me the reason behind it and What should be done to avoid it .\[code\] <script type="text/javascript"> function TextBox1_TextChanged() { <% Session["HitCount1"] = TextBox1.Text ; %> } function getMyvalSession() { var ff = "Loading Value"; return ff; } </script><body> <form id="form1" runat="server"> <asp:TextBox ID="TextBox1" Name="TextBox1" runat="server" AutoPostBack='true' onchange="TextBox1_TextChanged()"></asp:TextBox> <% string x = null; x = Session["HitCount1"].ToString().Trim(); if ((x.Equals(null)) || (x.Equals(""))) { // Session Variable is either empty or null . } else { TextBox1.Text = Session["HitCount1"].ToString(); } %> </form></body> protected void Page_Load(object sender, EventArgs e) { // Loading(); } void Loading() { String csname = "OnSubmitScript"; Type cstype = this.GetType(); // Get a ClientScriptManager reference from the Page class. ClientScriptManager cs = Page.ClientScript; // Check to see if the OnSubmit statement is already registered. if (!cs.IsOnSubmitStatementRegistered(cstype, csname)) {string cstext = " document.getElementById(\"TextBox1\").value = http://stackoverflow.com/questions/15596011/getMyvalSession() ;";cs.RegisterOnSubmitStatement(cstype, csname, cstext); } }\[/code\]
 
Back
Top