在ASP.NET中的页面加载时调用JavaScript [英] Calling javascript on page load in ASP.NET

查看:79
本文介绍了在ASP.NET中的页面加载时调用JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面加载时通过以下方式从代码后面调用javascript,它可以正常工作,但是当我在弹出/对话框中打开同一页面时,它不起作用


I am calling javascript from code behind in following way on page load it works fine but when it doesnt work when i open same page in popup/dialog box


If Not ClientScript.IsStartupScriptRegistered("") Then
 Page.ClientScript.RegisterStartupScript(Me.[GetType](), "", "fillexchange();", True)
 End If





是否有任何特殊原因





Is there any partcular reason

推荐答案

如果使用window.open语法打开了弹出窗口/对话框,那么它将起作用.但是,如果您使用的是JQuery或类似对话框,则它会起作用不会触发此事件,因为对话框的上下文将是已在其中注册脚本的当前页面.

问候,
Prasad P. Khandekar
If your popup/dialog is opened using window.open syntax then it will work.But if you are using JQuery or similar dialogs then it wont fire this event as the context of the dialog will be the current page in which the script is already registered.

Regards,
Prasad P. Khandekar


您需要将此代码添加到父页面的Page_Load中.它将起作用.
You need to add this code on the Page_Load of parent page. It will work.


我做到了
Page.ClientScript.RegisterStartupScript(Type.GetType("System.String"), "addScript", "fillexchange()", True)


这篇关于在ASP.NET中的页面加载时调用JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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