When using global variables and ajax, you need to re-assign them on each request, because when RadAjax starts an Ajax request, it will dispose the old object to minimize the chance for memory leaks. If you do not reassign the global variable you will end up with the old non-functional disposed object after the ajax request returns. Here is a sample code that will share more light on the matter:
| ASPX |
Copy Code |
|
<body onload="documentloaded()"> <form id="form1" runat="server"> <script type="text/javascript"> var globalvar; function documentloaded() { globalvar = <%= RadControl1.ClientID %>; } </script>
.........
</form> </body> |
[CodeBehind]
Here we reassign the global variable so the new object is available after ajax request:
| C# |
Copy Code |
|
protected void Page_Load(object sender, EventArgs e) { if (RadAjaxManager1.IsAjaxRequest) { RadAjaxManager1.ResponseScripts.Add( string.Format("globalvar = window['{0}']", RadControl1.ClientID)); } } |
| VB.NET |
Copy Code |
|
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If RadAjaxManager1.IsAjaxRequest Then RadAjaxManager1.ResponseScripts.Add( String.Format("globalvar = window['{0}']", RadControl1.ClientID)) End If End Sub |