0

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?

Christos
  • 53,228
  • 8
  • 76
  • 108
jestges
  • 3,686
  • 24
  • 59
  • 95

2 Answers2

2

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;
Christos
  • 53,228
  • 8
  • 76
  • 108
2

You can use a HiddenField.

The LinkButton does not implement IPostBackDataHandler, therefore it doesn't load postback data.

You can write the HiddenField.Value on client- and read it on serverside.

Here's a tutorial-video: [How Do I:] Use a Hidden Field to Store and Manipulate Client-Side Information

Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939