question

CindyMello-5714 avatar image
0 Votes"
CindyMello-5714 asked YijingSun-MSFT answered

Ajax Update Panel ScriptManager.RegisterStartupScript redirect Parent from iframe not working

I have an aspx page, c#, that loads in Ajax Update Panel. After page loads I override Page_Render so that I can save the page content as a pdf. After writing the file I want to redirect parent (my page is inside iframe) to another location on same site. I put the script to redirect inside void
private void RedirectWindowHome()
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectit", "parent.window.location = '/sites/service/zones/default.aspx'", true);
}
I call that from inside the overridden page render
protected override void Render(HtmlTextWriter writer)
{
//setup tw and write file..............

         if (!System.IO.File.Exists(pathString2))
         {
             File.WriteAllBytes(pathString2, pdfBytes);
         }
         else
         {
             Console.WriteLine("File \"{0}\" already exists.", fileName);
             return;
         }
         //file does write and I move to next line 
         RedirectWindowHome();
         // I even tried putting in button click and button clicks but no redirect
         Button1_Click(Button1, EventArgs.Empty);
  }

protected void Button1_Click(object sender, EventArgs e)
{
RedirectWindowHome();
}

so I am thinking that script does not register however on another form in the web app the same code
private void RedirectWindowHome()
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectit", "parent.window.location = '/sites/service/zones/default.aspx'", true);
}
is used on a button click, the submit button and the code fires and redirects.
Is it because I am not posting back? However that is why I tried using button click (programmatically) and that does not work.

Too many days with an old app - help?

Cindy

dotnet-csharpdotnet-aspnet-general
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

There is also a Q&A ASP.NET Webform tag you can post to for help.

0 Votes 0 ·

To check that the script is executed, maybe try this:

ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectit", "ale rt('TEST')", true);

If it works, you should see a message box.


0 Votes 0 ·

1 Answer

YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered

Hi @CindyMello-5714 ,
As far as I think, redirectit will not process JavaScript that is written out to the output stream other than JavaScript that is registered through the ClientManager on postback. This is more related with the way javascript works. the addition of script nodes can't simply be done by adding text to the inner HTML property of a div (this is what is done when the script nodes sent on the content panel element that is returned from the server). when you use register, the server side sends those elements on a different xml element and these kind of elements gets "special" treatment on the client side.
You could refer to below article:
https://www.aspsnippets.com/Articles/Display-Show-JavaScript-Alert-Message-Box-from-Resource-file-in-ASPNet.aspx
Best regards,
Yijing Sun


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.