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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I open a new window upon selection from a dropdownlist?

Status
Not open for further replies.

j9

Programmer
Jun 6, 2001
90
US
Hi,

I'm new to .net and I want to accomplish something I used to do in javascript...When a user clicks on a selection from a dropdownlist, I want to open a different page in a new window (while keeping the original window open). The value of the selected option must be passed to the new page and I don't want to pass it in a URL. My dropdownlist is a server control with an arraylist as a datasource.

Thanks for any help!
 
You will have to wire up an onSelectionChange event to your drop down list at runtime, what i suggest you do is create a javaScript function in a seperate .js file (as you would any other javaScript function) and then wire up the javaScript event to your list box.

The way you wire up the event to the drop down list is quite simple, fiddly at first but cool when you get used to it!

say for example your drop down list is called ddl1

Code:
'Wire Up JavaScript
ddl1.Attributes.add("OnChange", "myJavaFunction(this);")

I havnt tested this, as i dont use lists in this way.

through the "this" object you should be able to extract the information you need for the selected record.

Hope this helps

Rob
 
Sorry in the body i said onSelectionChange it should be onChange.

Rob
 
Do you mean the SelectedIndexChanged event in mywebform.aspx.cs?

Also, where does 'ddl1.Attributes.add("OnChange", "myJavaFunction(this);")' find out what .js file to go to?

Thanks!
 
Hi j9,

i apologise for my lack of knowledge with regards to events that can be wired up to a drop down list, i always forget them if i dont use them for a while.

in the html view of your webform you can specify a linked (or several linked) js files

Code:
<script language=javascript src="yourfile.js" type=text/javascript></script>

Your link is now created. if the myJavaFunction function is in yourfile.js and you have linked yourfile.js to your aspx page then it will idenity it. All the attributes.add does is allow you to specify over events that may happen client side for particular server side controls. All server side controls have attributes which can be manipulated to work as you wish

Hope that helps,

Rob
 
Thanks to all. Here's my final solution:
<HEAD>

<SCRIPT LANGUAGE=”JavaScript”>

/*

-Populate the value of the hidden input in form frmGetAnimal with the AnimalID from the selected item in the dropdown list.

-Submit form frmGetAnimal, which opens DisplayAnimal.aspx in a new browser window and passes it the AnimalID to be viewed.

*/

function getAnimal(myDropdown)

{

frmGetAnimal.hidAnimalID.value = myDropdown[myDropdown.selectedIndex].value;

frmGetAnimal.submit();

}

</SCRIPT>

</HEAD>

<BODY>

<!—This additional form is used to open the DisplayAnimal.aspx window when the user selects an animal from the dropdown. The ‘target=”_blank” attribute opens it in a new browser window while the original calling window remains open. -->
<form name="frmGetAnimal" action="DisplayAnimal.aspx" method="post" target="_blank">

<input type="hidden" name="hidAnimalID">

</form>


<form name="form1" runat="server">
<!-- Add an OnChange event to the DropDownList tag. -->

<asp:DropDownList id="lstAnimal" OnChange="getAnimal(this)" runat="server">
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top