Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6874873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:14:59+00:00 2026-05-27T04:14:59+00:00

In ASP.NET upon making a button click I need one JavaScript to make its

  • 0

In ASP.NET upon making a button click I need one JavaScript to make its action. I tried OnClientClick function but the problem with this event is first OnClientClick function takes place and then OnServerClick function takes place i.e. first JavaScript function runs and then C# code executes but I need in reverse order first I need to execute C# code and then I have to run the JavaScript. I am using AJAX.NET and ScriptManager in my code. Do scriptmanager helps me anyway? else how to run JavaScript on server side.

I need in the below manner.

Button1_Click(object sender, EventArgs e)
{
    ListBox1.Items.Add(TextBox1.Text); //for example
    ` here I have to run JavaScript `
}

Is there any way to implement this?

Edit 1:

I need a div to be scrolled down onbuttonclick(on click adds new data to div using databinder and repeater). As said above clientclick is running first but I need to run it after server action.

javascript is..

<script>
            var objDiv = document.getElementById("div1");
            objDiv.scrollTop = objDiv.scrollHeight;
</script> 

and

<div id="div1"> //css properties height 200 and width 200 overflow:auto
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
    <asp:Timer ID="Timer1" runat="server" Interval="200" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Repeater id="Repeater1" runat="server" >
        <ItemTemplate>
            <%# DataBinder.Eval(Container.DataItem, "Message") %> <br />
        </ItemTemplate>
        </asp:Repeater>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> 
    </Triggers>
    </asp:UpdatePanel>
    </div>
    <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <div id="div2">
            <asp:TextBox ID="tb_message" runat="server" Width="250px" EnableViewState="false" />
            <br />
            <asp:Button ID="btn_send" runat="server" Width="250px" Text="Send" 
                onclick="btn_send_Click" />
        </div>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btn_send" EventName="click" />
    </Triggers>
    </asp:UpdatePanel>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:14:59+00:00Added an answer on May 27, 2026 at 4:14 am

    EDIT

    Based on the code provided this should work if you would like to register the script on the server side:

    Button1_Click(object sender, EventArgs e)
    {
        ListBox1.Items.Add(TextBox1.Text); //for example
    
        ScriptManager.RegisterStartupScript(UpdatePanel2, UpdatePanel2.GetType(), "scriptKey", "var objDiv = document.getElementById('div1'); objDiv.scrollTop = objDiv.scrollHeight;", true);
    }
    

    You can use the code provided by James as well if you would like to register the script on the client side, but keep in mind that the script will be executed each time the AJAX request will be completed (The script will be executed each time any of the update panels is refreshed). If you are going to scroll down the div1 element each time the UpdatePanel1 is refreshed and there are no more update panels that are refreshed using the Timer control on the same page the code provided by James would be more useful, while my code will scroll down the div1 only of the button send is pressed.

    UPDATED

    i’m sorry – it seems that the code is executed after the server click event handler is executed, but before the html inside the first update panel is reloaded (you can simply set a breakpoint inside the server click event handler, and an alert in the registered script). So at the point when the script is executed the div element still contains old html.

    As a hack you can use a setTimeout function with a small timeout (in my sample 100 ms is quite enough). I’m looking for a proper way to check if the html inside update panel is reloaded and will update my answer as fast as I find it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to print PDF's generated in an asp.net application using crystal reports. Upon
I have a this asp.net page which upon first time load: 1: Make a
I have an ASP.NET page with a simple form and a submit button. Upon
Iam using forms authentication in asp.net Application,i want to make pages accessible depending upon
I have a ASP.Net MVC form that upon submit I need a couple of
I have a button on my asp.net page that (upon mouseover) needs to act
Hi I am developing a simple application based upon ASP.NET MVC. I have altered
I am embarking upon my first ASP.NET MVC project and I would like to
I've got an ASP.NET app using NHibernate to transactionally update a few tables upon
I am working on an asp.net web site that is based upon a single

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.