将动态生成的Javascript添加到C#ASP.NET页的最佳方法是什么? [英] What is the best way to add dynamically generated Javascript to a C# ASP.NET page?

查看:69
本文介绍了将动态生成的Javascript添加到C#ASP.NET页的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个用户页面上,该页面需要从用户选择中更新下拉列表.需要进行更新时触发的控件的唯一事件是Javascript事件.我需要预加载两个Javascript函数,以便在需要更新列表之前发生的回发中,从数据库查询中重新填充下拉列表.插入我可以从该页面事件中调用的Javascript函数的最佳方法是什么?

感谢您的帮助.

I am working on a user page that needs to update dropdown lists from a user selection. The only event for the control that is triggered when the update needs to occur is a Javascript event. I need to preload two Javascript functions to repopulate dropdown lists from a database query on a postback that occurs before the lists need to be updated. What is the best way to insert Javascript functions that I can call from that page event?

Thanks for your help.

推荐答案

您可以在
<script src="../Common/Scripts/jquery.min.js" type="text/javascript"></script>


或者,您可以使用


Or you can use

Page.ClientScript.RegisterClientScriptInclude or RegisterClientScriptBlock

,然后实际上要从PageLoad中调用函数之一

and then to actually call one of the functions from the PageLoad you would do

Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "FunctionToRun();", true);


引用该线程
http://stackoverflow.com/questions/6211183/dynamic-javascript-in-asp-net [ ^ ]
Refer this thread
http://stackoverflow.com/questions/6211183/dynamic-javascript-in-asp-net[^]


这篇关于将动态生成的Javascript添加到C#ASP.NET页的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆