【问题标题】:Calling javascript from code behind从后面的代码调用 javascript
【发布时间】:2023-03-20 01:27:01
【问题描述】:

我有一个 c# asp.net 3.5 应用程序 我试图在某个事件之后从代码后面打开一个窗口。我有这个但它不工作并且firebug中没有错误

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()));
                }
            }
        }

有什么想法吗?

【问题讨论】:

    标签: javascript asp.net code-behind


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      当您查看源代码时,页面加载后,这段代码是否真的呈现到源代码中? 您能否在this.Page.ClientScript... 行设置断点,以验证这两个条件是否实际满足?

      【讨论】:

        猜你喜欢
        • 2019-09-06
        • 2011-12-02
        • 1970-01-01
        • 1970-01-01
        • 2013-03-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多