Hi friends
Well i done some trails like a idiot but i am struck some where do refer attachment and help me out ..!!
HELP me to make my code perfect
TY
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 12, 2013, 9:23 AM EDT
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication17.WebForm3" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace WebApplication17
{
public partial class WebForm3 : System.Web.UI.Page
{
int rent = 0, acost = 0;
protected void Button1_Click(object sender, EventArgs e)
{
if (RadioButton1.Checked==true)
rent = Convert.ToInt32(RadioButton1.ToolTip);
else if (RadioButton2.Checked == true)
rent = Convert.ToInt32(RadioButton2.ToolTip);
if (CheckBox1.Checked == true)
acost = Convert.ToInt32(CheckBox1.ToolTip);
if (CheckBox2.Checked == true)
acost = Convert.ToInt32(CheckBox2.ToolTip);
int total = acost + rent;
Label1.Text = "registered " + "" + TextBox1.Text + ":rent/day
" + total;
clear();
}
void clear()
{
TextBox1.Text = "";
RadioButton1.Checked = false;
RadioButton2.Checked = false;
CheckBox1.Checked = false;
CheckBox2.Checked = false;
}
}
}
SUNIL GUTTARank #1,831 · 810 reputationPosted Mar 12, 2013, 10:17 AM EDT
Vishal GilbileRank #268 · 9.4K reputationPosted Mar 12, 2013, 8:41 PM EDT
what i've understood from your problem is that you need to set the AutoPostback property of the RadioButton and Checkboxes to true if you are not getting the proper selection.
Hope that solves your problem.
With Regards,
Vishal Gilbile.
SUNIL GUTTARank #1,831 · 810 reputationPosted Mar 13, 2013, 8:33 AM EDT
Vishal Gilbile Here there is no need for auto post back to set TRUE for radio & checkboxes
Satyapriya Nayak here in ur answered post as well as my in my attachment there a minor error of judgement i.e here it goes [in ur code we don't require clear without this replace below code we get it ]
Under check-boxes condition the correct way is
if (CheckBox1.Checked == true)
acost = Convert.ToInt32(CheckBox1.ToolTip);
if (CheckBox2.Checked == true)
acost = acost + Convert.ToInt32(CheckBox2.ToolTip); & remove clear() & logic of it :)
If replace this in ur & my code we get the o/p :)
Sorry for the trouble & ty for replies :) TY