如何从JavaScript访问ASPxTextBox的价值 [英] How to access the value of an ASPxTextBox from JavaScript
问题描述
假设我有一个DevEx preSS ASPxTextBox id为文书。我想在客户端访问文本框的值。所以,我需要写一个javascript。
如果这是一个正常的asp文本框,我可以写code像
VAR instrumentElement =的document.getElementById('&LT访问的文本框; %= instrument.ClientID%GT;')
但是,同样的方法是行不通的DevEx preSS的文本框。
我怎样才能访问ASPxTextBox?我使用的开发防爆preSS版本7.2。
下面是一些更彻底code片段 -
< DIV的风格=显示:内联;浮动:左;>
< DXE:ASPxTextBox ID =InstrumentQuantity=服务器WIDTH =170像素>
< / DXE:ASPxTextBox>
< / DIV>< DIV的风格=显示:内联;浮动:左;的onclick =incOrDecQty(0);>
< ASP:ImageButton的ID =decrementQuantity=服务器
HEIGHT =16像素WIDTH =16像素的ImageUrl =〜/图片/ left.png
还有AlternateText =减少数量一项PostBackUrl =JavaScript的:无效(0);/>
< / DIV>&所述;股利的onclick =incOrDecQty(1);>
< ASP:ImageButton的ID =incrementQuantity=服务器
还有AlternateText =增加数量的ImageUrl =〜/图片/ right.png
HEIGHT =16像素WIDTH =16像素一项PostBackUrl =JavaScript的:无效(0); />
< / DIV>
这是ASP code。相应的JavaScript如下:
函数incOrDecQty()
{
VAR元=的document.getElementById('<%= InstrumentQuantity.ClientID%GT;');
VAR lotSize = parseInt函数(的document.getElementById('<%= LotSize.ClientID%GT;')
.innerHTML,10);
VAR CurrentValue的= parseInt函数(element.value,10); 如果(参数[0] == 1)
CurrentValue的+ = lotSize;
否则如果((CurrentValue的 - lotSize)GT; = 0)
CurrentValue的 - = lotSize; element.value = CurrentValue的;
}
您可以设置在AspxTextBox的ClientInstanceName财产。
< DXE:ASPxTextBox ID =InstrumentQuantity
=服务器WIDTH =170像素
ClientInstanceName =MyTextBox>
< / DXE:ASPxTextBox>
客户方:
函数DoSomething的()
{
变种theText = MyTextBox.GetValue(); //的GetValue()是DevEx preSS客户方的功能 MyTextBox.SetValue('这是我想使用的值'); //设置文本}
该devex preSS文件对他们的客户端脚本一些pretty好的信息。转到此链接,单击参考,然后单击DevEx press.Web在菜单上.ASPxEditors.Scripts
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屋!