Search code examples
c#asp.netasplinkbutton

Read asp.net link button text from server side


net page with two controls

  1. linkbutton
  2. button

While running my application, I'm changing my link button text using javascript function.

Now I want to read that text when I press button. Button event is there in server side.

When I try to read like below

string s = linkButton.Text;

It is not giving my updated text.

How can I get it?


Solution

  • At first, declare this HiddenField in your markup

    <asp:HiddenField ID="link" runat="server" />
    

    Then in the function, you change the link button text, you should add the following code, in order the new text to the HiddenField been added.

    document.getElementById(<%=link.ClientID%>).setAttribute("Value",newText);
    

    Last, in your server side code you can get the value you want with the following way:

    string s = link.Value;