Remo
Remo

Reputation: 389

Highlighting HTML table when a link in the table is clicked

I have a lengthy asp.net page. A HTML table in the page has a link. when the link is clicked the page refreshes and takes me to the top part of the page. Instead, i want to see the part of the page that has the link. It should automatically scroll down to that part once the page refreshes. How is that possible.

Really appreciate your help. Thank you!

Upvotes: 1

Views: 173

Answers (3)

Craig O
Craig O

Reputation: 852

Add MaintainScrollPositionOnPostBack="True" in the page directive.

Upvotes: 2

Chuck Savage
Chuck Savage

Reputation: 11955

To color a row you can do this by using HtmlAgilityPack and by using a unique ID per table row, you can do:

HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);

var rows = doc.DocumentNode.SelectNodes("tr");
var linkRow = rows.FirstOrDefault(node =>
{
    HtmlAttribute a = node.Attributes["id"];
    if (null == a) return false;
    return "idLookingFor" == a.Value;
});
linkRow.Attributes.Add("bgcolor", "red"); 

Upvotes: 0

Forgotten Semicolon
Forgotten Semicolon

Reputation: 14130

If you're using ASP.NET 2.0 or above, and that is a LinkButton doing a postback, you can use:

<%@ Page MaintainScrollPositionOnPostback="true" %>

Upvotes: 1

Related Questions