Link to home
Create AccountLog in
ASP.NET

ASP.NET

--

Questions

--

Followers

Top Experts

Avatar of rito1
rito1

PostBackUrl Page to Open in New Window
Hi all

Within my webform I have 3 buttons. One of these buttons uses the postbackurl property to take the user to a print friendly version of the page.

Please could anyone suggest how I could modify the following button to open the target page in a new window without affecting the behaviour of the other 2 buttons on my original page?

<asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="print.aspx" />

My intial thought was to use the <base target="_blank"></base> within the head tags but this is applied to the whole page.

Many thanks

Rit

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of skiltzskiltz🇳🇿

<asp:Button ID="Button1" runat="server" Text="Button" />

---code behind---

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Button1.Attributes.Add("onclick", "window.open('print.aspx')")
    End Sub

Avatar of Carl TawnCarl Tawn🇬🇧

If its not doing a postback then it doesn't really need to be an asp:button, a simple HTML button will suffice:

    <input type="button" value="Button" onclick="window.open('print.aspx');" />

Avatar of rito1rito1

ASKER

Hi skiltz

Thanks for your time.

This works great to open the page in a new window but at the same time it also changes the original page to this destination too. Is there any way of keeping the original page available without affecting the postbackurl function?

Rit


Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of rito1rito1

ASKER

thank you carl_tawn,

It is doing a postback.

Rit


Avatar of skiltzskiltz🇳🇿

Did you remove  PostBackUrl="print.aspx"

ASKER CERTIFIED SOLUTION
Avatar of skiltzskiltz🇳🇿

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of rito1rito1

ASKER

THanks skiltz, I'll give this a go. I haven't removed postbackurl as I thought I needed this still to be able to access the controls from the previous page.

Rit

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


Avatar of rito1rito1

ASKER

Hi kiltz,

This seems to produce the right behaviour. I have left the postbackurl attribute in my control and it seems to not cause any issues.

Adding the javascript, would this stop the functioning of the postbackurl?... I can't actually test this at the moment as I am having issues within the whole postbackurl thing within a separate string...

https://www.experts-exchange.com/questions/22641815/PreviousPage-FindControl-'Object-reference-not-set-to-an-instance-of-an-object.html

Once I have resolved this I can confirm your solution.

Again. many thanks for your valuable contributions.

Rit
ASP.NET

ASP.NET

--

Questions

--

Followers

Top Experts

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications