Set custom control property value through javascripthttp://forums.asp.net/t/1793742.aspx/1?Set+custom+control+property+value+through+javascriptThu, 19 Apr 2012 01:51:05 -040017937424936510http://forums.asp.net/p/1793742/4936510.aspx/1?Set+custom+control+property+value+through+javascriptSet custom control property value through javascript <p>Hi,</p> <p>How to set the property value of custom control through javascript. Below is the code snippet used in my custom control.</p> <pre class="prettyprint">[ToolboxData(&quot;&lt;{0}:ServerControl1 runat=server&gt;&lt;/{0}:ServerControl1&gt;&quot;)] public class ServerControl1 : WebControl { [Category(&quot;Misc&quot;)] public string SelectedText { get; set; } }</pre> <p></p> <p>&nbsp;</p> 2012-04-17T11:05:54-04:004936564http://forums.asp.net/p/1793742/4936564.aspx/1?Re+Set+custom+control+property+value+through+javascriptRe: Set custom control property value through javascript <p>refer:</p> <p><a href="http://stackoverflow.com/questions/5577986/how-to-get-javascript-value-property-for-custom-textbox-control-in-asp-net">http://stackoverflow.com/questions/5577986/how-to-get-javascript-value-property-for-custom-textbox-control-in-asp-net</a></p> <p><a href="http://www.codeproject.com/Questions/74875/Access-custom-server-control-property-in-javascrip">http://www.codeproject.com/Questions/74875/Access-custom-server-control-property-in-javascrip</a></p> <p></p> 2012-04-17T11:27:51-04:004936583http://forums.asp.net/p/1793742/4936583.aspx/1?Re+Set+custom+control+property+value+through+javascriptRe: Set custom control property value through javascript <p>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).&nbsp; 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.</p> 2012-04-17T11:33:02-04:004936592http://forums.asp.net/p/1793742/4936592.aspx/1?Re+Set+custom+control+property+value+through+javascriptRe: Set custom control property value through javascript <p></p> <blockquote><span class="icon-blockquote"></span> <h4>thomas.watson12</h4> refer: <p></p> <p><a href="http://stackoverflow.com/questions/5577986/how-to-get-javascript-value-property-for-custom-textbox-control-in-asp-net">http://stackoverflow.com/questions/5577986/how-to-get-javascript-value-property-for-custom-textbox-control-in-asp-net</a></p> <p><a href="http://www.codeproject.com/Questions/74875/Access-custom-server-control-property-in-javascrip">http://www.codeproject.com/Questions/74875/Access-custom-server-control-property-in-javascrip</a></p> </blockquote> <p></p> <p>Both of these example show how to get the value on the client.&nbsp; However, this question is regarding setting the value on the server from the client.</p> 2012-04-17T11:37:38-04:004936616http://forums.asp.net/p/1793742/4936616.aspx/1?Re+Set+custom+control+property+value+through+javascriptRe: Set custom control property value through javascript <p>Hi,</p> <p>The examples shown in the below link is not working.. null is returned always..</p> <p>Example: alert<span class="pun">(</span><span class="str">'&lt;%=ServerControl1.SelectedText %&gt;'</span><span class="pun">);</span><span class="pln">&nbsp;&nbsp;&amp;&amp; alert(document.getElementById(<span class="code-string">&quot;ServerControl1</span><span class="code-string">&quot;</span>).SelectedText );<br> </span></p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>thomas.watson12</h4> <p></p> <p>refer:</p> <p><a href="http://stackoverflow.com/questions/5577986/how-to-get-javascript-value-property-for-custom-textbox-control-in-asp-net">http://stackoverflow.com/questions/5577986/how-to-get-javascript-value-property-for-custom-textbox-control-in-asp-net</a></p> <p><a href="http://www.codeproject.com/Questions/74875/Access-custom-server-control-property-in-javascrip">http://www.codeproject.com/Questions/74875/Access-custom-server-control-property-in-javascrip</a></p> <p></p> <p></p> </blockquote> <p></p> 2012-04-17T11:52:28-04:004939892http://forums.asp.net/p/1793742/4939892.aspx/1?Re+Set+custom+control+property+value+through+javascriptRe: Set custom control property value through javascript <p>Theorily speakingyou cannot do thatas what&nbsp;stevenbey's said</p> <p>However I've got a cluemaybe you can create something like a HiddenField in the event of ChildControlCreated or some event like thatand everytime in the Load event of your controltry to use something like Request.Forms[&quot;id of that hiddenfield&quot;] to read out strings included by that hiddenfield and assign to the public propertyAnd you can use js to automatically change the hiddenfield's value</p> <p>Reguards</p> 2012-04-19T01:51:05-04:00