ASP.NET WebForms + Postback, then open a popup

I have a LinkButton that needs to do a postback in order to execute some logic.

Once this is finished, instead of loading the page in a browser, I want to leave it alone and open a new window.

So far, the best idea I have set is to set LinkButton in UpdatePanel and make it display some JavaScript when it restarts, but I think it is absolutely hacky. Also, if I remember correctly, JavaScript in the update panel will not work anyway.

Any other ideas?

+3
source share
3 answers

LinkButton.PostBackUrl, POST, script, ( , postbacks ). PreviousPage, .

<script runat="server">
   void lnk_Click(object sender, EventArgs e) {
      // Do work
   }
</script>

<script type="text/javascript">
   var oldTarget, oldAction;
   function newWindowClick(target) {
      var form = document.forms[0];
      oldTarget = form.target;
      oldAction = form.action;
      form.target = target;

      window.setTimeout(
         "document.forms[0].target=oldTarget;"
         + "document.forms[0].action=oldAction;", 
         200
      );
   }
</script>

<asp:LinkButton runat="server" PostBackUrl="Details.aspx" Text="Click Me"
  OnClick="lnk_Click"
  OnClientClick="newWindowClick('details');" />
+6

:

protected void Button1_Click(object sender, EventArgs e)

{

// Do some server side work

string script = "window.open('http://www.yahoo.com','Yahoo')";

if (!ClientScript.IsClientScriptBlockRegistered("NewWindow"))

{

ClientScript.RegisterClientScriptBlock(this.GetType(),"NewWindow",script, true);

}

}
+2

One thing you could try is to associate the LinkButton OnClick event with its processing, and then register the page.ClientScript.RegisterStartupScript file with pop-up code, causing some Javascript in the tag to light up after the page loads. This should start your new window after processing is complete.

EDIT: After reading your comment, I believe that you can still use this approach, your results are stored in a session variable, and then a pop-up page displays the results.

+1
source

All Articles