文本框的属性 [英] Properties of Textbox
本文介绍了文本框的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi Geeks,
asp.net中文本框属性的一个小小疑问
我只需4个文本框
a = 4(文本框)
b = 2(文本框)
c = 2(文本框)
d = 4(文本框)....就像一个例子..
我乘以b&c并将结果放在d上。当d(文本框)在文本框中有一些值时,我应该检查a和d是否相等,否则会抛出错误。
可以在文本框的OnLoad函数中完成这个吗?
Hi Geeks,
Just a small doubt in textbox properties in asp.net
I just 4 textbox
a=4(Textbox)
b=2(Textbox)
c=2(Textbox)
d=4(Textbox) .... Just as an example..
I multiply b & c and put the result on d. When d(Textbox) has some value in textbox, I should check whether a and d are equal, if not will throw an error.
Can be done this in OnLoad function of a textbox ??
推荐答案
没有OnLoad函数对于TextBox。
你可以这样做
1)将B和C文本框乘以
There is no OnLoad function for TextBox.
You can do like this
1) multiply B and C Textbox as
TxtBox_D.Text = Convert.ToInt32(TxtBox_B.Text) * Convert.ToInt32(TxtBox_C.Text) ;
并查看价值为
and check the values as
if( TxtBox_A.Text != TxtBox_D.Text )
{
throw new Exception("not matching");
}
你可以在客户端使用javascript或jQuery进行验证
you can validate in client side using javascript or jQuery
<input type="text" id="a" value="0" />
<input type="text" id="b" value="0"/>
<input type="text" id="c" önkeyup="calc()" value="0"/>
<input type="text" id="d" value="0"/>
function calc() {
document.getElementById('d').value = parseInt(document.getElementById('c').value) * parseInt(document.getElementById('b').value);
if (document.getElementById('a').value == document.getElementById('d').value) {
alert("matching values");
}
}
Demo[^]
if you need to do it with asp:TextBox
<asp:TextBox ID="a" runat="server" ClientIDMode="Static"></asp:TextBox> <asp:TextBox ID="b" runat="server" ClientIDMode="Static"></asp:TextBox>
<asp:TextBox ID="c" runat="server" onchange="javascript:calc();" ClientIDMode="Static">/asp:TextBox>
<asp:TextBox ID="d" runat="server" ClientIDMode="Static"></asp:TextBox>
这篇关于文本框的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文