You can't set the property value directly, ie using JavaScript (which is on the client) to set the value of the control (which on the server). Without knowing how the control gets rendered, it's difficult to say what you need to do but one possible solution
is to set the value of a hidden field and then assign the value of the Form item to the control's property during PostBack.
Theorily speaking,you cannot do that——as what stevenbey's said……
However I've got a clue——maybe you can create something like a HiddenField in the event of ChildControlCreated or some event like that,and everytime in the Load event of your control,try to use something like Request.Forms["id of that hiddenfield"] to read
out strings included by that hiddenfield and assign to the public property……And you can use js to automatically change the hiddenfield's value。
anandhan
Member
1 Points
44 Posts
Set custom control property value through javascript
Apr 17, 2012 11:05 AM|LINK
Hi,
How to set the property value of custom control through javascript. Below is the code snippet used in my custom control.
[ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")] public class ServerControl1 : WebControl { [Category("Misc")] public string SelectedText { get; set; } }thomas.watso...
Member
182 Points
51 Posts
Re: Set custom control property value through javascript
Apr 17, 2012 11:27 AM|LINK
refer:
http://stackoverflow.com/questions/5577986/how-to-get-javascript-value-property-for-custom-textbox-control-in-asp-net
http://www.codeproject.com/Questions/74875/Access-custom-server-control-property-in-javascrip
stevenbey
All-Star
16526 Points
3378 Posts
Re: Set custom control property value through javascript
Apr 17, 2012 11:33 AM|LINK
You can't set the property value directly, ie using JavaScript (which is on the client) to set the value of the control (which on the server). Without knowing how the control gets rendered, it's difficult to say what you need to do but one possible solution is to set the value of a hidden field and then assign the value of the Form item to the control's property during PostBack.
http://stevenbey.com
Recursion: see Recursion
stevenbey
All-Star
16526 Points
3378 Posts
Re: Set custom control property value through javascript
Apr 17, 2012 11:37 AM|LINK
Both of these example show how to get the value on the client. However, this question is regarding setting the value on the server from the client.
http://stevenbey.com
Recursion: see Recursion
anandhan
Member
1 Points
44 Posts
Re: Set custom control property value through javascript
Apr 17, 2012 11:52 AM|LINK
Hi,
The examples shown in the below link is not working.. null is returned always..
Example: alert('<%=ServerControl1.SelectedText %>'); && alert(document.getElementById("ServerControl1").SelectedText );
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Set custom control property value through javascript
Apr 19, 2012 01:51 AM|LINK
Theorily speaking,you cannot do that——as what stevenbey's said……
However I've got a clue——maybe you can create something like a HiddenField in the event of ChildControlCreated or some event like that,and everytime in the Load event of your control,try to use something like Request.Forms["id of that hiddenfield"] to read out strings included by that hiddenfield and assign to the public property……And you can use js to automatically change the hiddenfield's value。
Reguards!