views:

43

answers:

3

I'm trying to call ScriptManager.RegisterStartupScript from page "A" so that when page "B" loads it displays an alert, but can't figure out how to get a reference to page "B" to satisfy the Control argument in the method call.

I figure there's got to be something similar to Page.FindControl() that does this, but I'm stuck...

A: 

Are you popping up page B in a new window with JavaScript?

If so you can access page A from B by using window.opener. You can use that to access some alert function (e.g. SendAlert(alert)) on page A. So on page B you can say window.opener.SendAlert("It opened");

BritishDeveloper
A: 

If "B" will run the script, then "B" must call RegisterStartupScript. Typically you would do this in the Page_Load event of page "B".

Ray
A: 

Register the startup script in page B. If you need to generate the script in page A, pass it to page B using one of the standard web mechanisms for persistence between pages ie querystring, hidden field, cookie , session variable, database. Normal caveats apply to each of those methods.

James Westgate