Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello

Say i 3 textboxes, the are named val1 , val2 and res. I show the addition result of values in val1 and val2 in res. So, if a user alters these values(i-e the values present in val1 and val2) res should be cleared. Example user enterd 2 in val1 and 3 in val2 so the addition result is 5 which is being shown in red textbox now say now user decides to change the value in val1 so when he begins to change i want my res text box to be cleared.

Beginner so please pardon my average questions

Thanks anyways
Posted
Updated 26-Dec-13 13:14pm
v2
Comments
BillWoodruff 26-Dec-13 20:06pm    
What event triggers the addition operation and the result being displayed in 'res ? Are you validating that both 'val1 and 'val2 contain numeric input ?

Have you tried implementing a handler of TextChanged[^] event on val1 and val2 textboxes? If you simply need res to be cleared when user inputs something into any of two other textboxes, just write in this handler:

C#
res.Text = string.Empty;
 
Share this answer
 
Here's one option, use javascript's onkeyup event on the client side to clear the result. When the user selects the val1 control and presses and releases a key the result value will be set to an empty string.
ASP.NET
<script type="text/javascript">
    // clear result
    function ResetResultValue() {
        var el = document.getElementById('<%= res.ClientID %>');
        el.value = '';
    }
</script>
    
<asp:textbox id="val1" runat="server" onkeyup="javascript:ResetResultValue();"></asp:textbox>
<asp:textbox id="val2" runat="server"></asp:textbox>
<asp:textbox id="res" runat="server"></asp:textbox>
<asp:button id="btnSubmit" runat="server" text="Submit" onclick="btnSubmit_Click" />
 
Share this answer
 
v2
Comments
Timberbird 26-Dec-13 23:54pm    
I'm not sure the original question was about web application. Since there weren't additional tags (namely ASP.NET), I decided it to be WinForms application - have I missed something?
SoMad 27-Dec-13 0:41am    
Not that I can see. Besides, your answer is C# as per the tag given by the OP.

Soren Madsen
idenizeni 27-Dec-13 11:41am    
Ah, good point, you are correct. I'm in web mode and obviously overlooked that bit.
loraloper_22 27-Dec-13 5:19am    
@timerbird Well yes the question was about WinForms application. Thanks a lot for your help. It did the trick.

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