如何从JavaScript访问ASPxTextBox的值 [英] How to access the value of an ASPxTextBox from JavaScript

查看:264
本文介绍了如何从JavaScript访问ASPxTextBox的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个DevExpress ASPxTextBox,其id是instrument。我想访问客户端的文本框的值。所以我需要写一个javascript。



如果这是一个普通的asp文本框,我可以通过编写代码(如

var instrumentElement = document.getElementById('<%= instrument.ClientID%>')

但是同样的方法不适用于DevExpress的文本框。



如何访问ASPxTextBox?我正在使用Developer Express版本7.2。



这是一些更全面的代码段 -

 < div style =display:inline; float:left;> 
< dxe:ASPxTextBox ID =InstrumentQuantityrunat =serverWidth =170px>
< / dxe:ASPxTextBox>
< / div>

< div style =display:inline; float:left;的onclick = incOrDecQty(0); >
< asp:ImageButton ID =decrementQuantityrunat =server
Height =16pxWidth =16pxImageUrl =〜/ images / left.png
AlternateText = 减少数量PostBackUrl =javascript:void(0);/>
< / div>

< div onclick =incOrDecQty(1);>
< asp:ImageButton ID =incrementQuantityrunat =server
AlternateText =增加数量ImageUrl =〜/ images / right.png
Height =16pxWidth =16pxPostBackUrl =javascript:void(0); />
< / div>

那是ASP代码。相应的Javascript如下:

  function incOrDecQty()
{
var element = document.getElementById ( '<%= InstrumentQuantity.ClientID%GT;');
var lotSize = parseInt(document.getElementById('<%= LotSize.ClientID%>')
.innerHTML,10);
var currentValue = parseInt(element.value,10);

if(arguments [0] == 1)
currentValue + = lotSize;
else if((currentValue - lotSize)> = 0)
currentValue - = lotSize;

element.value = currentValue;
}


解决方案

您可以设置ClientInstanceName属性在AspxTextBox上。

 < dxe:ASPxTextBox ID =InstrumentQuantity
runat =serverWidth =170px
ClientInstanceName =MyTextBox>
< / dxe:ASPxTextBox>

ClientSide:

 code> function DoSomething()
{
var theText = MyTextBox.GetValue(); // GetValue()是DevExpress客户端函数

MyTextBox.SetValue(这是我想要使用的值); //设置文本

}

devexpress文档有一些很好他们的客户端脚本的信息。转到此链接,单击参考,然后单击DevExpress.Web.ASPxEditors。菜单上的脚本。


Suppose I have an DevExpress ASPxTextBox whose id is "instrument". I want to access the value of the text box at client side. So I need to write a javascript.

If it was a normal asp text box, I could have accessed the text box by writing code like

var instrumentElement = document.getElementById('<%=instrument.ClientID%>')

But the same approach is not working for the DevExpress's Text Box.

How can I access an ASPxTextBox ? I am using Developer Express Version 7.2.

Here is some more thorough code snippet -

<div style="display: inline; float: left;">
    <dxe:ASPxTextBox ID="InstrumentQuantity" runat="server" Width="170px">
    </dxe:ASPxTextBox>
</div>

<div style="display: inline; float: left;" onclick="incOrDecQty(0);">
    <asp:ImageButton ID="decrementQuantity" runat="server" 
            Height="16px" Width="16px" ImageUrl="~/images/left.png" 
            AlternateText="Decrease Quantity" PostBackUrl="javascript:void(0);"/>
</div>

<div onclick="incOrDecQty(1);">
    <asp:ImageButton ID="incrementQuantity" runat="server" 
            AlternateText="Increase Quantity" ImageUrl="~/images/right.png" 
            Height="16px" Width="16px" PostBackUrl="javascript:void(0);" />
</div>

That was the ASP Code. The corresponding Javascript is as follows :

function incOrDecQty()
{
    var element = document.getElementById('<%=InstrumentQuantity.ClientID%>');
    var lotSize = parseInt(document.getElementById('<%=LotSize.ClientID%>')
        .innerHTML, 10);
    var currentValue = parseInt(element.value,10);

    if(arguments[0] == 1)
        currentValue += lotSize;
    else if((currentValue - lotSize) >= 0 )
        currentValue -= lotSize;

    element.value= currentValue;            
}

解决方案

You can set the ClientInstanceName property on the AspxTextBox.

<dxe:ASPxTextBox ID="InstrumentQuantity" 
 runat="server" Width="170px" 
 ClientInstanceName="MyTextBox"> 
</dxe:ASPxTextBox> 

ClientSide:

function DoSomething()
{
    var theText = MyTextBox.GetValue(); //GetValue() is the DevExpress clientside function

    MyTextBox.SetValue('this is the value i want to use'); //Sets the text

}

The devexpress documentation has some pretty good info on their client side scripts. Go to this link, click on Reference, then click on DevExpress.Web.ASPxEditors.Scripts on the menu.

这篇关于如何从JavaScript访问ASPxTextBox的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆