admin管理员组文章数量:1317906
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?
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?
Share Improve this question edited May 23, 2017 at 12:32 CommunityBot 11 silver badge asked May 15, 2012 at 17:19 SoenhaySoenhay 4,0586 gold badges38 silver badges61 bronze badges2 Answers
Reset to default 5If 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.
You could hack something...
Basically, as you dynamically create the textboxes give them a unique client instance name.
At then end of your page load, you can emit some javascript that declares and array and sets the elements to equal the textbox objects.
var ServerSideList = new List<string>();
while(CreatingTextBoxes)
{
...
ServerSideList.Add(uniqueTextboxName);
}
....
var sb = new System.Text.StringBuilder();
sb.AppendLine("var clientSideList = [];");
foreach(var s in ServerSideList)
{
sb.Append("clientSideList.push(");
sb.Append(s);
sb.AppendLine(");");
}
AspLiteralObject.Text = sb.ToString();
In the client side button click event, you could then iterate over the clientSideList array.
<script type="text/javascript">
function btnClick(s, e) {
var i;
var theTxtBx;
for(i = 0; i < clientSideList.length; i++)
{
theTxtBx = clientSideList[i];
theTxtBx.SetText('some text');
}
}
</script>
本文标签: javascriptHow to access a DevExpress ASPx control via JSProperties on the clientStack Overflow
版权声明:本文标题:javascript - How to access a DevExpress ASPx control via JSProperties on the client - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742030475a2416349.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论