微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net – 如何从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="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>

这就是ASP代码.相应的Javascript如下:

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;            
}

解决方法

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

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

客户端:

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

}

devexpress文档在客户端脚本上有一些非常好的信息.转到此link,单击Reference,然后单击菜单上的DevExpress.Web.ASPxEditors.Scripts.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐