0

I have a homepage that has two titles on. these titles link to another page (news.aspx). The news articles on news.aspx are stored in an accordion style.

What I want is: When the title of the news article is clicked on the homepage, it will redirect to that news.aspx page and the accordion section relating to that title will already be open.

Is there any way that this can be done please?

I know I need to create a function () but im not too sure how to go about it.

Jon Egerton
  • 40,401
  • 11
  • 97
  • 129
Reidy0588
  • 45
  • 1
  • 3
  • 11
  • first you need to find a way to get the data to the news.aspx page. I would pass a parameters in the URL and look for that value in your javascript load page event – musefan Jan 12 '12 at 10:11
  • so if the url was http://(blah blah bla)/news.aspx?id=461 indicating that the news article clicked was from a database with ID 461? then go about loading that into the javascript load event? – Reidy0588 Jan 12 '12 at 10:14
  • What have you tried so far, what didn't work? Or is this just a "please do it for me"? – Constantin Groß Jan 12 '12 at 10:15
  • Yes you could set the ID (from database) as the ID for each accordion element. Then you can easily find it. [here is one option](http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery) to get the parameter with javascript – musefan Jan 12 '12 at 10:19
  • connum i have tried [link](http://stackoverflow.com/questions/2199716/jquery-accordion-open-specific-section-on-pageload) and many others like it however this did not work as i am not a javascript programmer so i dont understand where to put things. in a way it is more like a "do it for me" lol – Reidy0588 Jan 12 '12 at 10:23
  • Please add an example of how the accordion you are using is constructed. Otherwise it's hard to know what data to work with. – Anders Arpi Jan 12 '12 at 11:02

2 Answers2

0

put this on load

if (Convert.ToInt32(Request.QueryString["lb"]) == 0) {
    MyAccordion.SelectedIndex = 0;
}
else if (Convert.ToInt32(Request.QueryString["lb"]) == 1) {
    MyAccordion.SelectedIndex = 1;
}

here is the accordion

<asp:Accordion ID="MyAccordion" runat="Server" SelectedIndex="0" Head

send the index from query string of the page you are redirecting.

ankitkanojia
  • 3,072
  • 4
  • 22
  • 35
Neha
  • 2,933
  • 3
  • 19
  • 23
0

I'm assuming that you're not using ASP.NET Accordion control but rather the jQuery UI .accordion() function.

You can then use the following jQuery UI function:

//select active accordion section
$("#accordion").accordion( "option", "active", $("."+currentNewsId) );

Plase check out this JSFiddle for a complete example: http://jsfiddle.net/wY7cr/2/

Everything you need to know should be in there. Please ask me if there are any questions.

Anders Arpi
  • 8,277
  • 3
  • 33
  • 49