I need to change the text of my linkbutton using Java Script

Posted on 2014-07-16
Last Modified: 2014-07-17
I have a very simple program. When my hyperlink button is clicked, I need to change the text on the button from "Clicked" to "Now Clicked". I need the text change to occur client side in my Java Script method SomeMethod(obj) .

Can someone help me out here, I cannot figure it out. The code below works, yet I cannot figure out how to change the text.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Test1 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        LinkButton lb = new LinkButton();
        lb.ID = "myLinkeButton";
        lb.Text = "UnClicked";
        lb.OnClientClick = "return SomeMethod(this)";
----------------------------------ASP.Net Code below--------------------------------------------
<html xmlns="">
<head runat="server">
    <script type="text/javascript">
        function SomeMethod(obj) {
            // In this method,
            // How do I change the text of my link button to "Now Clicked";
            return false;
    <form id="form1" runat="server">

Question by:brgdotnet
    LVL 142

    Accepted Solution

    this should do:

     lb.OnClientClick = "return SomeMethod('myLinkeButton')";

    <script type="text/javascript">
           function SomeMethod(id) {
                     var fieldNameElement = document.getElementById(id);
                     id.Text = "some other text";
                   return false;
    LVL 19

    Assisted Solution

    by:Albert Van Halen
    Be aware that using ASP.NET the id on the client is different than on the server. Use ClientID property of the control.
    Passing 'this' refers to the element already which is better imo.
    You should indeed set the text property in order to change (but use lowercase !)
    <script type="text/javascript">
        function SomeMethod(obj) {
            obj.text = 'Now Clicked';
            return false;

    Open in new window


    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Article by: DanRollins
    This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (, we'll extend the program by adding a depth-…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now