Calling javascript from code behind
Asked Answered
L

2

1

I have a c# asp.net 3.5 app I am trying to open a window from code behind after a certain event. I have this but its not working and there are no errors in 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()));
                }
            }
        }

Any ideas?

Legitimist answered 1/12, 2009 at 20:10 Comment(0)
H
4

Assuming that the pre-conditions are true. You need to pass an additional parameter to the RegisterClientStartupScript method call to indicate that scriptTags need to be added.

Page.ClientScript.RegisterStartupScript(this.GetType(), "openCredentials", string.Format("radopen('Services.aspx?clientId={0}, Window_Services')", openCredentialsWindow_ClientId.ToString()),true);
Hiroko answered 1/12, 2009 at 20:15 Comment(0)
C
1

When you view the source, after page load, is this code actually rendered into the source? Can you set a breakpoint at the this.Page.ClientScript...-line, to verify that both conditions before it are actually met?

Cyclosis answered 1/12, 2009 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.