Question

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?

Was it helpful?

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;

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top