1

I am using the following code to open the file with dropdown selected value from a url

Protected Sub ddlPS_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPS.SelectedIndexChanged
        ClientScript.RegisterStartupScript(Me.GetType(), "openfile", String.Format("var w = window.open('http://foods.shakarganj.com.pk/pdf/{0}.pdf');", ddlPS.SelectedValue), True)
    End Sub

Problem is that when i select the Value from dropdown it opens the file in window and also refresh the parent page.I want to avoid the the parent refreshing and want to open the file in new tab intead of in new window.

Adeel Aslam
  • 1,285
  • 10
  • 36
  • 69

3 Answers3

1

Your dropdown change is causing a postback to the server. You can avoid this behavior turning off the auto postback and binding a client script event to open the new window on a new tab.

The solution you need: ASP.Net Open New Tab in Browser from CodeBehind.

Community
  • 1
  • 1
Rui Marques
  • 3,429
  • 1
  • 22
  • 26
0

In firefox this will work, add target _newtab on your window.open

var w = window.open('http://foods.shakarganj.com.pk/pdf/{0}.pdf','_newtab');

For IE you have to force users to change browser configuration, so that new windows will be opening as tabs

Emmanuel N
  • 7,350
  • 2
  • 26
  • 36
0

To prevent page refresh use jquery to open link:-

<script type="text/javascript">
        $(document).ready(function () {
            $('#<%=ddlPS.ClientID %>').change(function (event) {
                event.preventDefault();
                var w = window.open('http://foods.shakarganj.com.pk/pdf/' + $(this).val() + '.pdf');
            });
        });
    </script>
Harvinder
  • 91
  • 2
  • 10