I know this might be an odd situation but currently I need to mix javascript with server side code as follows:
function PerformGlobalCallback(sender, value) {
var index = hfCurrentTabIndex.Get("activeIndex"));
window['<%= ((ASPxCallbackPanel)myTabControl.TabPages[index].Controls[0]).ClientInstanceName %>'].PerformCallback(sender + "|" + value);
}
where hfCurrentTabIndex is a hidden field which correctly holds the value of the current tab index.
I know I cannot simply put the “index” variable in the <%= %> section so I need to come up with a way to do it.
The reason I need this is because the myTabControl current tab index is somehow lost in between callbacks. Also, even though I store it in Session, I get null when I access it in the above code.
Please let me know if you have any insights. Appreciate your help.
That should do what you want.
Server side code is processed first so the page gets sent to the client browser before the client browser processes the JavaScript. You could also use an AJAX call to get the .ClientInstanceName. But the way demonstrated above builds the JavaScript array on the server for you, so your client code just has to look-up the index.
Note The code was written inside my browser window and is not tested, so syntax errors may exist.