Voici ce qui a fonctionné pour moi. Javascript a ceci.
<script type="text/javascript">
var deptname = '';
</script>
C# Code derrière a ceci - il pourrait être mis sur la page principale de sorte qu'il réinitialise var sur chaque changement de page.
String csname1 = "LoadScript";
Type cstype = p.GetType();
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = p.ClientScript;
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
String cstext1 = funct;
cs.RegisterStartupScript(cstype, csname1, "deptname = 'accounting'", true);
}
else
{
String cstext = funct;
cs.RegisterClientScriptBlock(cstype, csname1, "deptname ='accounting'",true);
}
Ajoutez ce code à un bouton de clic pour confirmer le changement de nom de département.
alert(deptname);