Question

I have master page. In master page I have one UserControl. In this UserControl I have one button . When I complete everything with this button event I want to call Javascript function from page. Below is my code :

Button Event

    protected void btnAddCompany_Click(object sender, EventArgs e)
    {
        // Do something Here

        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alertmessage();", true);
    }

Javascript Function On same UserControl

    <script type="text/javascript">
   function alertmessage() {
       alert("Call Successfull");
   }
 </script>

But this javascript function never been called. When same UserControl is inside page it works. but if it is inside masterpage it doesn't.

Était-ce utile?

La solution

The above code works. Make sure if you have user ScriptManager.RegisterStartupScrip anywhere other part of the page then you have terminate Javascript code with ;. If inline javascript fails, no other function is called.

Refer: ScriptManager.RegisterStartupScript code not working - why?

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top