0

In my application i create a navigation menu dynamically. When I click on the anchor tags that refer to various content page I want to capture the anchor tags' text and display it in a div in the content page.

How can i possibly achieve this?

Can it be done through HttpHandlers? or do I need to look into something else??? Please help.

Jackson Lopes
  • 215
  • 1
  • 5
  • 20
  • Have you tried using `Request.Url` in content page? – B0Andrew Jul 25 '14 at 04:48
  • No. kindly enlighten me on the topic. How could I go about using that?? – Jackson Lopes Jul 25 '14 at 04:50
  • I need to change the title div of a lot of content pages based on the menu clicked. So, I cant possibly go around writing code in the content page's code behind. I need something subtle. Like some code that changes the content page div when i click the master page menu. Thanks... – Jackson Lopes Jul 25 '14 at 04:59
  • Then why don't you put your div in the master page and write code in master page's `Page_Load`? Explain your problem better. You want that div to have different styles for each content page? – B0Andrew Jul 25 '14 at 05:10
  • Sorry for the trouble. – Jackson Lopes Jul 25 '14 at 05:16
  • Yes. I could do what you just said. Thanks Andrew. Let me get back to you with the verdict. Thanks a ton man. – Jackson Lopes Jul 25 '14 at 05:22

1 Answers1

1

Assuming that you want your div to look different or be positioned in different places for each content page and all you want to display in that div is the page URL you can solve this using a simple script that you can add in your master page:

document.onload = function()
{
    var titleDiv = document.getElementById("titleDiv");
    titleDiv.innerText = window.url;
}

The only constraint is that your div must have the same id in all the content pages.

B0Andrew
  • 1,725
  • 13
  • 19
  • nothing happens. I've included the code in my master page but nothing happens. I included a debugger in the javascript and came to know that it's never called. – Jackson Lopes Jul 25 '14 at 07:07
  • i made it work but now the window.url return undefined so i get undefined in my div. – Jackson Lopes Jul 25 '14 at 07:12
  • Thanks. I got it. url must URL...Thanks A ton. Now I got the url in the div, is there anyway in which i could get the innerHTML of the tag in the div. – Jackson Lopes Jul 25 '14 at 07:19
  • Also Andrew, I accomplished the task by placing a div in master and changing its text. When I try to access a content page div like u mentioned it gave a null reference exception. Thanksss – Jackson Lopes Jul 25 '14 at 09:32
  • Mission Accomplished. Thanks a ton Andrew for pointing me in the right direction. Much appreciated. – Jackson Lopes Jul 25 '14 at 11:38