Pergunta

I have a method which return type is string. From the method i want to call a javascript method which is inside .aspx page.But the javascript method is not getting called. below is my code

private string test()
{
   if(somecondition)
   {
       ScriptManager.RegisterStartupScript(Page, GetType(), "HideSlider1", "HideSlider();", true);
   }
   return stringvalue;
}
Foi útil?

Solução

Use ClientScript class instead of ScriptManager

private string test()
{
   if(somecondition)
   {
       ClientScript.RegisterStartupScript(Page.GetType(), "HideSlider1", "HideSlider();", true);
   }
   return stringvalue;
}

Outras dicas

Try this.

private string test()
{
    if(somecondition)
    {
         ScriptManager.RegisterClientScriptBlock(Page, GetType(), "HideSlider1", "<script type='text/javascript'>HideSlider();</script>", true);
    }
    return stringvalue;
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top