Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Launching a new window from a dropdown list

  Asked By: Lourdes    Date: Sep 07    Category: Asp.net    Views: 2056
  

I want to launch a new window from a standard server control dropdown
list.I need to do it from inside the "Dropdown1.SelectedIndexChanged"
event because if I do it before that, I can't capture
the "Dropdown1.SelectedItem.Text" to pass to the next page. I tried
adding a "onchange" event to the attributes,
like "Dropdown1.Attributes.Add("onchange", "window.open, etc" , but
then it launches the window first and never gets inside
the "Dropdown1.SelectedIndexChanged" event, thus no text to capture???

As if that's not enough of a request, does anyone know the best way
to pass this selected item text to the next page? I read in the .NET
Developers Guide something about writing a class to reference back to
the first page. Surely there has to be an easier way to add server
control text values to a Request Object or some other method.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Raju Srinivas     Answered On: Sep 07

With adding attributes  like this - Dropdown1.Attributes.Add - you're adding client side event. And if you want to access the selected  item from client script you have to use something like Form1.selID.value.....

But as you say, you want to use SelectedIndexChanged server-side event. So you have to write your client-script in that event  - after it's started. You could add  script with RegisterClientScriptBlock like this:


private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
string strUrlToOpen = DropDownList1.SelectedItem.Value.ToString();
string strOpenWinScript = "<script language='JavaScript'>window.open('" + strUrlToOpen + "','','toolbar=0');</script>";
this.RegisterClientScriptBlock("OpenWinScript",strOpenWinScript);
}

and now, if you set AutoPostBack property od your DropDownList, on PostBack will be your script in the output and new window  will open.

 
Didn't find what you were looking for? Find more on Launching a new window from a dropdown list Or get search suggestion and latest updates.




Tagged: