best way to do this, list of urls

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!
 
Y

Yankee Imperialist Dog

(no cop-out intended here)
see the AJAX tool kit on asp.net this may give you options with out a lot of
work
 
G

Göran Andersson

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;");
 
P

Paul

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;");
 
G

Göran Andersson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top