简体   繁体   中英

Dispose control

Design:

在此处输入图片说明

If i don't have any land component price/flight prices to be added, i want the system to dispose the unused controls and move up to fill in the empty spaces, but somehow or rather, it became like this.

Result:

在此处输入图片说明

if (bf.landComponent != 0.00m)
{
    lblLandComponent.Text = "" + bf.landComponent;
    lblLandComponent.Visible = true;
    lblLandComponentL.Visible = true;
}
else
{
    lblLandComponent.Dispose();
    lblLandComponentL.Dispose();
}

if (bf.flightComponent != 0.00m)
{
    lblFlightComponent.Text = "" + bf.flightComponent;
    lblFlightComponent.Visible = true;
    lblFlightComponentL.Visible = true;
}

if (bf.unitSales != 0.00m)
{
    lblUnitSales.Text = "" + bf.unitSales;
    lblUnitSales.Visible = true;
    lblUnitSalesL.Visible = true;

}

if(bf.rentalCar!=0.00m)
{
    lblCT.Visible = true;
    lblRentalCar_L.Visible = true;
    lblRentalCar.Visible = true;
    lblRentalCar.Text = "" + bf.rentalCar;
}

if (bf.discount != 0.00m)
{
   lblDiscount.Text = "" + bf.discount;
   lblDiscountL.Visible = true;
   lblDiscount.Visible = true;
}

if(bf.packageInclusion!="")
{
   lblPackageInclusion.Text = bf.packageInclusion;
   lblPackageInclusion.Visible = true;
   lblPackageInclusionL.Visible = true;
}
//BF is a class object stored in a session that i put from the previous page.

Is there something wrong?

The Dispose method is not for the thing you want. Check in the docs to see what it really does.

When you want to hide a control, try setting their Visibility to false , or try removing them from their parent container control.

Conditionally setting their Visibility to true is not enough. In 99% of cases they would be visible anyways, since that's the default value for visibility. You must ensure to either set their initial Visibility to false, or add else clause that will do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM