Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ??
Posted
Comments
Bh@gyesh 4-Jun-14 2:42am    
Why you need to calculate onLoad function. You can use textchange event of textboxes.
Sriram Ramachandran 4-Jun-14 2:49am    
I doesn't know which property to use? Using OnTextChange, Only after typing the method gets invoked.

There is no OnLoad function for TextBox.
You can do like this
1) multiply B and C Textbox as
C#
TxtBox_D.Text =   Convert.ToInt32(TxtBox_B.Text) * Convert.ToInt32(TxtBox_C.Text) ;


and check the values as

C#
if( TxtBox_A.Text != TxtBox_D.Text )
{
throw new Exception("not matching"); 
} 
 
Share this answer
 
Comments
Sriram Ramachandran 4-Jun-14 2:54am    
as soon as the TextBox_D got value in its textbox, I need to throw a message. So I need to write only on TextBox_D method. Which method would be apt one?
Karthik_Mahalingam 4-Jun-14 3:00am    
you need to perform the action in client side ( javascript) or server side ( asp, c#) ??
Sriram Ramachandran 4-Jun-14 3:08am    
Yeah atlast, I am trying that...
you can validate in client side using javascript or jQuery
HTML
<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"/>

JavaScript
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.NET
<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>
 
Share this answer
 
v3
Comments
Sriram Ramachandran 4-Jun-14 3:10am    
I am using <asp:Textbox>. How to use onkeyup in this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900