0

I do have a linkbutton and i want it to call an event on the .cs file (OnClick Event that do something).

BUT I also want to make this button moves the scroll to certain div after.

I can do:

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="doSomething_Click">DoSomething!</asp:LinkButton>

And it does call the doSomething_Click event correctly.

OR I can do:

<asp:LinkButton ID="LinkButton1" runat="server" href=#MainDiv>DoSomething!</asp:LinkButton>

And it does scroll to the "MainDiv" after clicking.

But I can't do both! href=#MainDiv and OnClick="doSomething_Click"

  • no, you can't do both as `LinkButton` utilises `onclick` event to trigger postback. if you want to do a postback then scroll down, register a js script after the postback triggered. ps. postback causes the image to reload. – Bagus Tesa Sep 22 '18 at 11:21
  • i do not know much about javascript but i was reading a bit, like adding a with something like this: $("button").click(function () { $('html,body').animate({ scrollTop: $(".second").offset().top }, 'slow'); }); but how I "call" it? – Facundo Díaz Sep 22 '18 at 11:40
  • Have a look at [ClientScriptManager.RegisterStartupScript](https://learn.microsoft.com/de-de/dotnet/api/system.web.ui.clientscriptmanager.registerstartupscript?view=netframework-4.7.2#System_Web_UI_ClientScriptManager_RegisterStartupScript_System_Type_System_String_System_String_System_Boolean_) – grek40 Sep 22 '18 at 16:50

0 Answers0