Within a website I need to switch panels during the load of a page based on a parameter set in code behind, and needs to be switched through javascript. The parameter is being included within the javascript function in code-behind but I am receiving an error of 'missing formal parameter', what may be the problem?
Here is the code that is generated by the RegisterClientScriptBlock:
<script language='javascript'>function switchactionpanel(1)</script>
Here is the code-behind that registers the script to call on load:
protected void Page_Init(object sender, EventArgs e)
{
String switchAction = "<script language='javascript'>function switchactionpanel(" + (int)((Global.upAction) Enum.Parse(typeof(Global.upAction), Global.ProfileAction.ToString())) + ")</script>";
Page.RegisterClientScriptBlock("switchaction", switchAction);
}
Here is the javascript function within the aspx file:
<script type="text/javascript">
function switchactionpanel(upaction) {
switch (upaction) {
case 1:
$('#urfcontainer').hide();
$('#rstcontainer').show();
break;
case 2:
$('#urfcontainer').show();
$('#rstcontainer').hide();
break;
};
}
</script>
It's because the generated javascript is wrong. You have a 'function' keyword too much. You get:
which doesn't make sense. Just make sure you get
and you should be fine. Remove the 'function' keyword here: