please provide the code ........

Posted by Srinunelli under ASP.NET on 3/15/2012 | Points: 10 | Views : 1286 | Status : [Member] | Replies : 6
i want percentage...
task:
three textboxes are there secured marks textbox1,total marks textbox2,percentage textbox3
main task is .....i enter value in textbox1 and enter value in textbox2 then automatically display percentage in textbox3 without click in textbox3(we should not enter percentage) and without click button.
percentage calculation:percentage=secured marks/total marks * 100;




Responses

Posted by: Patel28rajendra on: 3/15/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

you can set Autopostback = true for second textbox and write code in ontextchanged event of second textbox


Thanks


R D Patel

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/15/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Srinunelli,
Try This:
 <form id="form1" runat="server">

<div>
SecuredMarks <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
TotalMarks <asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True"
ontextchanged="TextBox2_TextChanged"></asp:TextBox>
<br />
Percentage <asp:TextBox ID="TextBox3" ReadOnly="true" runat="server" Width="295px"></asp:TextBox>

</div>
</form>


protected void TextBox2_TextChanged(object sender, EventArgs e)

{
TextBox3.Text = Convert.ToDecimal(100* decimal.Parse(TextBox1.Text) / decimal.Parse(TextBox2.Text)).ToString();
}


Click Mark As Answer if it works for you

Thanks,
Sanjay

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/15/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Srinunelli,
After you enter data in textbox2 press tab or click any other control.You need to come-out of that control.
Do appropriate validation as per requirement.

Thanks,
Sanjay

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Denny on: 3/16/2012 [Member] Starter | Points: 25

Up
0
Down
Hi
<form id="form1" runat="server">
<div>

Secured Marks<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
Total Marks <asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True"
ontextchanged="TextBox2_TextChanged"></asp:TextBox>
<br />
<br />
Percentage <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>

</div>
</form>

protected void TextBox2_TextChanged(object sender, EventArgs e)
{
TextBox3.Text = ((Convert.ToDecimal(TextBox1.Text) / Convert.ToDecimal(TextBox2.Text)) * 100).ToString();
}

Regards,
Denny Kurian

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 3/19/2012 [Member] Bronze | Points: 25

Up
0
Down

Hi

YOu Can USe This Code


protected void TotalPercentage_TextChanged(object sender, EventArgs e)

{

TotalPercentage.Text = Convert.ToDecimal(100* (Convert.ToDecimal(Mark1.Text)) /(Convert.ToDecima(Mark2.Text))).ToString();

}


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rajni.Shekhar on: 3/20/2012 [Member] Bronze | Points: 25

Up
0
Down
hi Srinunelli,
You can also use javascript OnBlur event to calculate percentage.
this.textbox2.Attribute["onBlur"]="javascript:return CalCulatePercentage()";

in javascript file,

function CalCulatePercentage()
{
//secured marks textbox1,total marks textbox2,percentage textbox3

var securedMarks=document.getElemtById("textbox1").value;
var totMarks=document.getElemtById("textbox2").value;

if(securedMarks == "")
{
alert("please enter secured marks.");
return false;
}
if(totMarks == "")
{
alert("Please enter total marks.");
return false;
}

document.getElemtById("textbox3").value = (parseFloat(securedMarks)/parseFloat(totMarks)) * 100;
return true;
}


Thanks,
Rajni Shekhar

Srinunelli, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response