Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Any one please provide me the code for C#..
 

    if tbfirstper==100 then tbsecondnominee,tbsecondper,tbthitdnominee,tbthirdper is not enable.
    If tbfirstper <100;then tbsecondnominee,tbsecondper is enable,
    if tbfirstper+tbsecondper<100, then tbthitdnominee,tbthirdper is enable,
 
 please help me how to write the code
Posted 20-Apr-13 22:55pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Start by converting tbfirstper.Text to a numeric value, usinf int.TryParse, or double.TryParse, depending on what datatype you expect:
 
int firstPer;
if (!int.TryParse(tbfirstper.Text, out firstper))
    {
    // Report problem to user
    return;
    }
Do the same for tbsecondper.
Then, disable all four texboxes.
Then, check your values:
if (firstPer < 100)
   {
   tbsecondnominee.Enabled = true;
   tbsecondper.Enabled = true;
   }
if (forstPer + secondPer < 100)
   {
   tbthitdnominee.Enabled = true;
   tbthirdper.Enabled = true;
   }
  Permalink  
Comments
prodipjsr at 21-Apr-13 4:11am
   
Sir, please tell me why i m using this code & where i will write this code???(in page load )
 
if (!int.TryParse(tbfirstper.Text, out firstper))
{
// Report problem to user
return;
}
OriginalGriff at 21-Apr-13 4:19am
   
Well, that is up to you, but I would have thought that a button click event would be a more suitable place - that way the user gets a chance to actually typing in your text boxes...
 
BTW: You do realize that the "Report problem to user" comment is meant to be somewhere that you actually do that? It won't do it itself?
prodipjsr at 21-Apr-13 5:19am
   
Sir, i hv written the code bellow, but when i put 100 in tbfirstper.Text then tbtbsecondper.text or others 3 text boxes cant disable..
please help me where is my mistake..more than 3 working days i hv try for this..please help...
 

private void Textbox_TextChanged(object sender, EventArgs e)
{
int firstPer, secondPer;
if (!int.TryParse(tbfirstper.Text, out firstPer))
{
// Report problem to user
return;
}
 
if (!int.TryParse(tbsecondper.Text, out secondPer))
{
// Report problem to user
return;
}
tbsecondnominee.Enabled = false; tbsecondper.Enabled = false;
tbthitdnominee.Enabled = false; tbthirdper.Enabled = false;
 

 
if (firstPer < 100)
{
tbsecondnominee.Enabled = true;
tbsecondper.Enabled = true;
}
if (firstPer + secondPer < 100)
{
tbthitdnominee.Enabled = true;
tbthirdper.Enabled = true;
}
 
}
OriginalGriff at 21-Apr-13 5:32am
   
The first thing to notice is that you don't want to do it like that. That kind of validation (on a text-box change) is definitely not suited to web applications - each character typed needs a round trip to the server to check it out. Slow, cumbersome and wasteful. You should do this kind f thing in Javascript at the client, not in the server.
prodipjsr at 21-Apr-13 5:37am
   
Sir i also try in javascript & the code is::But it also not work::
 
<script type="text/javascript">
$(document).ready(function () {
$("#tbfirstper,#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper :input").each(function () {
var v1 = $("#tbfirstper").val(),
v2 = $("#tbsecondper").val();
if (!isNaN(v1)) {
if (parseInt(v1, 10) == 100) {
$("#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").attr("disabled", "disabled");
 
}
else if (parseInt(v1, 10) < 100) {
$("#tbthitdnominee,#tbthirdper").attr("disabled", true);
$("#tbsecondnominee,#tbsecondper").attr("disabled", true);
}
if (!isNaN(v2)) {
if ((parseInt(v2, 10) + parseInt(v1, 10)) == 100) {
$("#tbthitdnominee,#tbthirdper").attr("disabled", true);
}
else if ((parseInt(v2, 10) + parseInt(v1, 10)) < 100) {
$("#tbthitdnominee,#tbthirdper").attr("disabled", false);
}
}
}
});
});
</script>
prodipjsr at 21-Apr-13 5:40am
   
wil u please give ur mail id?? i will send u the project for doing this ..please help me..i cnt understand why these r not working..
prodipjsr at 21-Apr-13 5:42am
   
Sir, i also try $("#tbfirstper,#tbsecondnominee,#tbsecondper,#tbthitdnominee,#tbthirdper").blur(function ()
 
but is also not workingggg

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

  Print Answers RSS
0 OriginalGriff 562
1 Sergey Alexandrovich Kryukov 484
2 Maciej Los 325
3 DamithSL 233
4 Mathew Soji 195
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 21 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100