I want to get the link url when i click on the link..

Topics: Developer Forum, Project Management Forum, User Forum
Jul 2, 2013 at 8:28 PM
in my default.aspx page in page load I am doing this.
When i click on the link it show error. i want to get the link url for clicked links, or when i click
on a link in session or variable it will return me url. i am tired of searching this thats why i am asking here.. please help me on this......


string url = "http://dl.acm.org";
    var webGet = new HtmlWeb();
    var document = webGet.Load(url);

    var linksOnPage = from lnks in document.DocumentNode.Descendants()
                      where lnks.Name == "a" &&
                           lnks.Attributes["href"] != null &&
                           lnks.InnerText.Trim().Length > 0
                      select new
                      {
                          Url = lnks.Attributes["href"].Value,

                      };


    var body = document.DocumentNode.Descendants()
                            .Where(n => n.Name == "body")
                            .FirstOrDefault();


    var linksThatDoNotOpenInNewWindow = document.DocumentNode.SelectNodes("//a[@href]");
    if (linksThatDoNotOpenInNewWindow != null)
    {
        foreach (var link in linksThatDoNotOpenInNewWindow)
        {
            if (link.Attributes["id"] == null)
            {
                int ID = 1;
                int newid = ID++;
                string id = "link"+ newid  ;
                link.Attributes.Add("id", id);
            }


            if (link.Attributes["href"] != null)
            {


            }

            //if (link.Attributes["target"] == null)
            //    link.Attributes.Add("target", "_blank");

            //else
            //    link.Attributes["target"].Value = "_blank";
        }
    }