Call javascript from code

I have a C # asp.net 3.5 application. I'm trying to open a window from code after a specific event. I have this, but it does not work 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?

+1
javascript code-behind
Dec 01 '09 at 20:10
source share
2 answers

Assuming the premises are correct. You need to pass an additional parameter to the RegisterClientStartupScript method call to indicate that you need to add script tags.

 Page.ClientScript.RegisterStartupScript(this.GetType(), "openCredentials", string.Format("radopen('Services.aspx?clientId={0}, Window_Services')", openCredentialsWindow_ClientId.ToString()),true); 
+4
Dec 01 '09 at 20:15
source share

When you browse the source, after the page loads, is this code really mapped to the source code? Can you set a breakpoint on the line this.Page.ClientScript... to make sure that both conditions are met before they are met?

+1
Dec 01 '09 at 20:15
source share



All Articles