从后面的代码调用 javascript

IT技术 javascript asp.net code-behind
2021-02-21 21:51:45

我有 ac# asp.net 3.5 应用程序 我试图在某个事件之后从代码后面打开一个窗口。我有这个,但它不工作,萤火虫没有错误

protected override void OnPreRender(EventArgs e) {
            base.OnPreRender(e);
            if (openCredentialsWindow) {
                if (openCredentialsWindow_ClientId != Guid.Empty) {
                    this.Page.ClientScript.RegisterStartupScript(this.GetType(), "openCredentials", string.Format("radopen('Services.aspx?clientId={0}, Window_Services')", openCredentialsWindow_ClientId.ToString()));
                }
            }
        }

有任何想法吗?

2个回答

假设前提条件为真。您需要向RegisterClientStartupScript方法调用传递一个附加参数,以指示需要添加 scriptTags。

Page.ClientScript.RegisterStartupScript(this.GetType(), "openCredentials", string.Format("radopen('Services.aspx?clientId={0}, Window_Services')", openCredentialsWindow_ClientId.ToString()),true);

查看源码时,页面加载后,这段代码是否真的渲染到了源码中?您能否在this.Page.ClientScript...-line处设置断点,以在实际满足之前验证这两个条件?