简体   繁体   English

如何从部分加载的ASPX页面的代码背后调用javascript函数

[英]How to call a javascript function from code-behind of a partially loaded aspx page

I have an asp.net application and I use jquery's .load function to load content into a specific div like so: 我有一个asp.net应用程序,我使用jquery的.load函数将内容加载到特定的div中,如下所示:

 $('#pnl').load('/Panel.aspx #panel', loadLogs());

From the Panel.aspx page I populate some dropdowns in the code-behind load event, and from there I have some javascript functions(in a separate javascript file) that display text files based on the content of the dropdowns, which is controlled by the change events on the dropdowns. 在Panel.aspx页面中,我在代码隐藏加载事件中填充了一些下拉菜单,从那里我有一些javascript函数(在单独的javascript文件中),这些函数根据下拉列表的内容显示文本文件,该文本文件由更改下拉菜单中的事件。 I am having an issue of when the page is loaded, the dropdowns are populated but I need to actually click on one of them to get the files to display. 我在加载页面时遇到问题,下拉列表已填充,但我实际上需要单击其中之一才能显示文件。 I have tried to call the javascript functions from the load event of Panel.aspx with Page.ClientScript.RegisterClientScriptBlock and they are not firing. 我试图从带有Page.ClientScript.RegisterClientScriptBlock的Panel.aspx的load事件中调用javascript函数,但它们没有触发。 I have also tried firing it from window.onload or $(document).ready from the javascript file and it is still not working. 我还尝试从javascript文件中从window.onload或$(document).ready触发它,它仍然无法正常工作。

Any suggestions for how I can get this done? 关于如何完成此工作的任何建议?

try something like this 尝试这样的事情

If you Used Update Panels Then You can Use: 如果您使用了更新面板,则可以使用:

ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "javascriptFunction();", true);

Other Wise You can Use 您可以使用的其他明智

ClientScript.RegisterStartupScript
        (GetType(),Guid.NewGuid().ToString(), "javascriptFunction();",true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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