Javascript – How to access a DevExpress ASPx control via JSProperties on the client

asp.netdevexpressjavascript

Lets say that I have several DevExpress controls and one of them is a button. On that button I want to add the ClientInstanceNames of each of the other controls so that I can access them in the buttons client side click event..

c#:

String strID = "MyButton";
ASPxButton btn =  new ASPxButton() { ClientInstanceName = strID , Text = "Click Here", Width = new Unit("100%"), AutoPostBack = false, CssFilePath = strCssFilePath, CssPostfix = strCssPostFix };
btn.ClientSideEvents.Click = "btnClick";
btn.JSProperties.Add("cp_MyTxtBx", strID );

I want to do something similar to this…

js:

<script type="text/javascript">
        function btnClick(s, e) {
            var theTxtBx = document.getElementById(s.cp_MyTxtBx);
            theTxtBx.SetText('some text');
        }
</script>

But that doesn't work.
I know that I could do it like this:

<script type="text/javascript">
        function btnClick(s, e) {
            MyTxtBx.SetText('some text');
        }
</script>

But these controls are dynamically created and I will not know their ClientInstanceNames until run time.

So, how can I get the control based on the String JSProperty of its ClientInstanceName?

Thanks in advance.

Related posts but not quite what I need:

How to access the value of an ASPxTextBox from JavaScript

DevExpress: How do get an instance of a control client-side and access its client-side members?

Best Answer

If I understood you correctly this is what you need:

var theTxtBx = window[s.cp_MyTxtBx];

Every devex control with ClientInstanceName set is registered as global variable.