<script language="javascript" type="text/javascript" function SetValue() { var myControl = document.getElementById('txtHidden'); if (myControl) document.forms[0].submit(); // Instead of this you can use ASP.NET's __doPostback code to fire the postback. If you use it, it's then possible to intercept this info in the page // __doPostBack('ControlOrEventCausingPostback', 'AnyParameters'); // In that case, you don't need the hidden input - pass the parameter as the second parameter of __doPostBack } </script <input type="hidden" name="txtHidden" / // In your ASP.NET code-behind: if (Page.IsPostBack) { string hiddenValue = Request.Form["txtHidden"]; // Do something // Or if you are using ASP.NET's __doPostBack you can do this in Page_Load: // string eventName = Request.Form["__EVENTTARGET"]; // string arg = Request.Form["__EVENTARGUMENT"]; // if (eventName == "ControlOrEventCausingPostback") // this.DoSomething(arg); }You can't easily persist variables between postback w/o just recreating them. What I normally do is just inject some JavaScript after the postback which calls the function you want, ex:
string script = "<script type=\"text/javascript\">JSFunctionToRun();</script>"; Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "JustNameOfScript", script); // You can actually call RegisterClientScriptBlock with a 4th parameter of true - that will add the <script tag stuff for you.This just tells ASP.NET to inject this JS code into the page. As soon as the browser loads it should run this code.