Question

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;
}
Was it helpful?

Solution

Use ClientScript class instead of ScriptManager

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

OTHER TIPS

Try this.

private string test()
{
    if(somecondition)
    {
         ScriptManager.RegisterClientScriptBlock(Page, GetType(), "HideSlider1", "<script type='text/javascript'>HideSlider();</script>", true);
    }
    return stringvalue;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top