Unable to run Autocomplete jQuery with dynamically created variable ASP.net?

thetimbosley

New Member
I am using jQuery Autocomplete code in javascript in aspx page. The code works fine when the data is declared in the script itself but when I pass the variable from code-behind to client script it doesn'tWork. \[code\]<script type="text/javascript"> $(function () {// var projects = [{value: "jquery", label: "jQuery", desc: "the write less, do more, JavaScript library", icon: "https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/yP/r/FdhqUFlRalU.jpg" },// {// value: "jquery-ui",// label: "jQuery UI",// desc: "the official user interface library for jQuery",// icon: "https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/yP/r/FdhqUFlRalU.jpg"// },// {// value: "sizzlejs",// label: "Sizzle JS",// desc: "a pure-JavaScript CSS selector engine",// icon: "https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/yP/r/FdhqUFlRalU.jpg"// }// ];// // alert(JSVar + JSVar1); $("#Text1").autocomplete({ minLength: 0, source: JSVar, focus: function (event, ui) { $("#Text1").val(ui.item.label); return false; } }) .data("autocomplete")._renderItem = function (ul, item) { return $("<li></li>") .data("item.autocomplete", item) .append("<a><img src='" + item.icon + "' width='32' height='32' /> " + item.label + "</a>") .appendTo(ul); }; $("#Text2").autocomplete({ minLength: 0, source: JSVar1, focus: function (event, ui) { $("#Text2").val(ui.item.label); return false; } }) .data("autocomplete")._renderItem = function (ul, item) { return $("<li></li>") .data("item.autocomplete", item) .append("<a><img src='" + item.icon + "' width='32' height='32' /> " + item.label + "</a>") .appendTo(ul); }; });\[/code\]In code-behind, Male and Female are my main data..\[code\] string str1 = "<script type=\"text/javascript\">var JSVar='" + Female + "'; var JSVar1='" + Male + "'; </script>"; ClientScriptManager script = Page.ClientScript; if (!script.IsClientScriptBlockRegistered(this.GetType(), "Var")) { script.RegisterClientScriptBlock(this.GetType(), "Var", str1.ToString()); }\[/code\]The code works fine when I use \[code\]var projects\[/code\] instead of \[code\]JSVar\[/code\] and \[code\]JSVar1\[/code\]. But not when I use JSVar and JSVar1 which is dynamically defined in the code-behind with same structure like projects.NOTE: I am able to get right values for JSVar and JSVar1 inside script on verifying them with alert() using ClientScriptManager.
 
Top