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

  • SEARCH
  • Home
  • 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 8512885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:24:13+00:00 2026-06-11T04:24:13+00:00

I am trying to call a javascript function from onClick event of an asp

  • 0

I am trying to call a javascript function from onClick event of an asp server button. I have this button and a label in an update panel.

In aspx:

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
       <ContentTemplate>
         <asp:Button ID="Button1" runat="server" 
            style="z-index: 1; left: 49px; top: 119px; position: absolute; height: 26px;" Text="Button" 
            onclick="Button1_Click"/>
         <asp:Label ID="Label1" runat="server" Text="l1" 
            style="position:absolute; top: 123px; left: 127px;"></asp:Label>
       </ContentTemplate>
    </asp:UpdatePanel>

Code behind:

protected void Button1_Click(object sender, EventArgs e)
{
   ScriptManager.RegisterClientScriptBlock(this, typeof(Button), "me", "me()", true);
}

Javascript in aspx:

<script type="text/javascript">
function me()
{
   document.getElementById('<%= Label1.ClientID %>').value="clicked";
}
</script>

All I am trying to do is on button click the label’s value should be changed to ‘clicked’, which isn’t happening and no error as well in firebug. Where am I wrong in the me( )?

P.S: I am doing this to learn calling a javascript function from code behind. So any optimizations to the code are also welcome. (I actually have much lot of code to implement in the JS function later so appropriate suggestions please)

  • 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-06-11T04:24:14+00:00Added an answer on June 11, 2026 at 4:24 am

    As far as I remember the Label control is rendered as a <div> or <span> (can’t remember exactly), not a text input field. So you should be setting its innerHTML property not the value:

    document.getElementById('<%= Label1.ClientID %>').innerHTML = 'clicked';
    

    or simply do it on the server side instead of registering clientside callbacks:

    protected void Button1_Click(object sender, EventArgs e)
    {
       Label1.Text = "clicked";
    }
    

    UPDATE:

    As requested in the comments section here’s how you could pass parameters to the clientside callback from the server:

    protected void Button1_Click(object sender, EventArgs e)
    {
        string param1 = ...
        double param2 = ...
        int param3 = ...
        var serializer = new JavaScriptSerializer();
    
        ScriptManager.RegisterClientScriptBlock(
            this, 
            typeof(Button), 
            "me", 
            string.Format("me({0})", serializer.Serialize(new { param1 = param1, param2 = param2, param3 = param3 })), 
            true
        );
    }
    

    and your callback:

    function me(values) {
        // you could use values.param1, values.param2, values.param3, ... here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to call a server side button click method from javascript function
I am trying to call c# function from javascript the code i have tried
I am trying to call a JavaScript function from an onclick trigger. HTML section:
I am trying to call a javascript function from asp.net codebehind using onclientclick for
I have a javascript function from where I am trying to call the serverside
I'm trying to have JavaScript call a function from my ActionScript. ActionScript: import flash.external.ExternalInterface;
I am trying to call a JavaScript function from icefaces check box component like
I am trying to call my function named isUrgencyTypeValid from my javascript code but
I am trying to call a WebMethod from JavaScript. So far I have: The
I'm trying to call a Flash function from javascript passing complex data types as

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.