RegisterClientScript not work for set array value

100 Views Asked by At

I define one array in my javascript.js file :

var rowPermissions = [];

and I set values in asp.net code as Client Script Block in my usercontrol.ascx page :

if (permission == true)
    folderPermissions = "rowPermissions[" + folderId + "] = '1';";
else
    folderPermissions = "rowPermissions[" + folderId + "] = '0';";

ScriptManager.RegisterClientScriptBlock(upExpander, upExpander.GetType(), "row Permission"+folderId + Guid.NewGuid(), folderPermissions, true);

but it won't work, and the array is not filled. why? and how can I solve this????

1

There are 1 best solutions below

0
giammin On BEST ANSWER

You give little infos so I can only guess that your array definition is executed later than the rendered script by RegisterClientScriptBlock.

Look at the html source of the page.

Try to use the ClientScriptManager.RegisterStartupScript Method instead

ClientScriptManager.RegisterStartupScript (...);