Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

opening a new browser window?

Status
Not open for further replies.

Sheffield

Programmer
Jun 1, 2001
180
US
Greetings,

(I'm a ASP.NET newbie...)

PROBLEM: I can't figure out how to open a new browser window (and display a *.pdf) based on the
Code:
SelectedItem.Value
property of a
Code:
DropDownList
.

Here is my ultra-simple code thus far...
Code:
<script>

</script>

<html>
<head>
	<title>Untitled</title>
</head>

<body>

<form runat=&quot;Server&quot;>

<asp:DropDownList id=&quot;drpExample&quot; AutoPostBack=&quot;True&quot; runat=&quot;server&quot;>
  <asp:ListItem Text=&quot;file 1&quot; Value=&quot;file1.pdf&quot; />
  <asp:ListItem Text=&quot;file 2&quot; Value=&quot;file2.pdf&quot; />
  <asp:ListItem Text=&quot;file 3&quot; Value=&quot;file3.pdf&quot; />            
</asp:DropDownList>

</form>

</body>
</html>

Can someone please clue me in?
 
Probaly easier to do this with client-side javascript as thats where you have the capability to open windows...

In the Page_Load event of your VB/C# codebehind file add the following (example in C#)....

drpExample.Attributes.Add(&quot;onchange&quot;, &quot;window.open(this.options[this.selectedIndex].value)&quot;);

This will add the client side event 'onchange' to the select list rendered by .NET for your dropdownlist. When the selected index of the list changes the event will fire the Javascript to open a new window and populate it with the value of the selected list item.

You will need to set AutoPostBack to false to stop the page refreshing as well.

I'm not sure how you would do this using inline asp.net (<script runat=&quot;server&quot;> tags) but you may have to use a <select runat=&quot;server&quot;> tag instead of an asp:dropdownlist and add the onchange event directly to the tag...

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
I use JavaScrit to open new windows. I just can't belive Microsoft doesn't have this feature in his .NET product??!!
 
ASP.NET is a server based scripting environment therefore it can't have any control over windows being opened on a client machine.

There are classes in the .NET framework to allow you to register client script blocks from your asp.net code and have these rendered to the response stream so you could capture the value of the selected item in the list on the server after postback and then regsiter a script block with the window.open command in. Just seems a long way around to do something thats fairly simple on the client.

Besides why have an extra round trip to the server when you don't need one?

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top