sai
sai

Reputation: 79

call a particular div id in c#

I am trying to call a particular div based on id in page_prerender event but it doesn't navigate to the particular div id.

<div id="div1">1</div>
<div id="div2">2</div>
<div id="div3">3</div>

protected void page_prerender()
{
   Response.Redirect("Default.aspx#div1");
}

Upvotes: 0

Views: 1384

Answers (3)

Sky5005e
Sky5005e

Reputation: 79

Please put runat="server". So, that you will able to access it on code behind

<div id="div1" runat="server">1</div>
<div id="div2" runat="server">2</div>
<div id="div3" runat="server">3</div>

Thanks

Upvotes: 0

IrishChieftain
IrishChieftain

Reputation: 15253

Use the FindControl method to locate the div - pass id of div as argument.

<div id="div1" runat="server">1</div>

FindControl("div1");

Upvotes: 2

sajanyamaha
sajanyamaha

Reputation: 3198

with jQuery Alternatively you can use this to scroll to specific element on page load with animation: try this on aspx page

$(function(){
   $('html, body').animate({ scrollTop: $("#div1").offset().top });
});

Upvotes: 0

Related Questions