简体   繁体   中英

Javascript call from C# not working when use RenderControl

I am following this article. http://www.codeproject.com/Articles/23768/Load-and-Display-Page-Contents-Asynchronously-with

I have a usercontrol with some javascript codes. Lets say there is a method called alertMe(msg) in javascript. And i am calling this from c#. It is not calling. i am using this.page.clientscript.registerscriptblock function.

Even the javascript is not rendered in the page. I did check it by pressing F12 in chrome browser and went to console and typed the method name, it said undefined.

  1. Will javascript not rendered in page when we use renderControl method
  2. While asynchronosly loading user controls, what is the way to call javascript methods from c#.

Have you tried ScriptManager instead of Page.ClientScript? I think that the script is not available during a partial postback if it is not registered with the ScriptManager.

Looks like this:

ScriptManager.RegisterStartupScript(Page, this.GetType(), "DatePickerScript" clientScript, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM