tags:

views:

47

answers:

4

Hello,

I have an ASP.NET page where I am dynamically building LinkButton and TextBox elements. These elements are being built during the OnInit event of the page. The user can then perform an action that changes the values of these elements. The values of these elements are changed via JavaScript. When the user clicks a button, a server-side event is fired. This event parses the value in each control. I have noticed that the value for the TextBox is correct, but the value for the LinkButton is not.

Can only certain types of controls in ASP.NET be dynamically generated and have their values retrieved on the server side?

Thank you.

A: 

No, generally you can create whatever element you like, given you create it inside the OnInit event or if you add the INamingContainer (marker) interface, you should override the CreateChildControls() method and create your elements in there.

But what do you mean by changing the value of the LinkButton via JavaScript? What exactly do you change on the LinkButton?? Could you provide more details?

Juri
A: 

Ensure that the "runat=server" property is set for each form element you want to retrieve via server code, and that you have an ID associated with each.

Jason Watts
+1  A: 

You can't get value of link button at server side. You can only get form elements' values at server side.

If you want to pass more values to server side, you can use hidden input elements.

Canavar
A: 

The textbox is working because value of the textbox is actually sent in the postback. But the linkbutton doesn't send anything back to the server. If you need to send something back that gets changed on the client, you'd need to set a hidden field and then modify your linkbutton using that value.

aquinas