best way to do this, list of urls

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

I have a web app that allows the user to create a list of urls. I am
currently have a textbox the user inputs the URL in one at a time and then a
button that when clicked adds the link to a dropdown list. Then for the
dropdown selected event I set the URL of a link button to the selected value
in the list.
Just wondering if you can have a dropdown list of hyperlinks? thanks!
 
(no cop-out intended here)
see the AJAX tool kit on asp.net this may give you options with out a lot of
work
 
Paul said:
Just wondering if you can have a dropdown list of hyperlinks? thanks!

No, you can't, but you can easily make the dropdown go to the selected
url (without even having to do another postback). Just add an onchange
event to the dropdown:

theDropdown.Attributes.Add("onchange",
"window.location=this.options[this.selectedIndex].value;");
 
thanks for the information. I did not see an onchange event from the event
property box of the dropdown but did find a TextChanged event. I added the
code below and set a break point. It does hit the break point but looks like
it is not going to the page, possibly a bad URL or should this work?

protected void drdn_links_TextChanged(object sender, EventArgs e)
{
this.drdn_links.Attributes.Add("onchange",
"window.location=this.options[this.selectedIndex].value;");
}
--
Paul G
Software engineer.


Göran Andersson said:
Paul said:
Just wondering if you can have a dropdown list of hyperlinks? thanks!

No, you can't, but you can easily make the dropdown go to the selected
url (without even having to do another postback). Just add an onchange
event to the dropdown:

theDropdown.Attributes.Add("onchange",
"window.location=this.options[this.selectedIndex].value;");
 
Paul said:
thanks for the information. I did not see an onchange event from the event
property box of the dropdown

That's because it's not a server event. I said that it didn't do a postback.
but did find a TextChanged event. I added the
code below and set a break point. It does hit the break point but looks like
it is not going to the page, possibly a bad URL or should this work?

protected void drdn_links_TextChanged(object sender, EventArgs e)
{
this.drdn_links.Attributes.Add("onchange",
"window.location=this.options[this.selectedIndex].value;");
}

You should not put the code in an event handler. The code adds a client
event to the control, so if you do it in an event handler, it will work
the second time that you change the dropdown.

Put the code in Page_Load.
 
Back
Top