Ok, I am trying to make 3 slider's value dependent on values of other 2, so they always add up to 100.
when i change one slider's value, the other slider's value gets changed too and then it just recursive on postback none stop. Is there anyway to make them not posting back if their value is changed through C# code behind?
when i change one slider's value, the other slider's value gets changed too and then it just recursive on postback none stop. Is there anyway to make them not posting back if their value is changed through C# code behind?
<telerik:RadSlider ID="RevenueSlider" runat="server" Skin="Vista" Length="150" SlideStep="2" |
OnValueChanged="RadSlider_ValueChanged" AutoPostBack="true" /> |
<br /> |
<telerik:RadSlider ID="CostSlider" runat="server" Skin="Vista" Length="150" SlideStep="2" |
OnValueChanged="RadSlider_ValueChanged" AutoPostBack="true"/> |
<br /> |
<telerik:RadSlider ID="SatisfactionSlider" runat="server" Skin="Vista" Length="150" SlideStep="2" |
OnValueChanged="RadSlider_ValueChanged" AutoPostBack="true" /> |
<br /> |
C# code |
public static int revvalue; |
public static int costvalue; |
public static int satvalue; |
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!IsPostBack) |
{ |
//InitializePerformanceSliders(); |
revvalue = 100; |
} |
RevenueSlider.Value = revvalue; |
CostSlider.Value = costvalue; |
SatisfactionSlider.Value = satvalue; |
} |
protected void RadSlider_ValueChanged(object sender, EventArgs e) |
{ |
int difference = 0; |
switch (((RadSlider)sender).ID) |
{ |
case "RevenueSlider": |
if ((revvalue != ((RadSlider)sender).Value) && (revvalue + 1 != ((RadSlider)sender).Value) && (revvalue - 1 != ((RadSlider)sender).Value)) |
{ |
difference = (revvalue - ((RadSlider)sender).Value) / 2; |
revvalue = ((RadSlider)sender).Value; |
if ((costvalue + difference) < 0) //if any field goes smaller than 0 |
{ |
satvaluesatvalue = satvalue + difference + (costvalue + difference); |
costvalue = 0; |
} |
else if ((satvalue + difference) < 0) |
{ |
costvaluecostvalue = costvalue + difference + (satvalue + difference); |
satvalue = 0; |
} |
else |
{ |
costvalue += difference; |
satvalue += difference; |
} |
} |
break; |
case "CostSlider": |
if ((costvalue != ((RadSlider)sender).Value) && (costvalue + 1 != ((RadSlider)sender).Value) && (costvalue - 1 != ((RadSlider)sender).Value)) |
{ |
difference = (costvalue - ((RadSlider)sender).Value) / 2; |
costvalue = ((RadSlider)sender).Value; |
if ((revvalue + difference) < 0) |
{ |
satvaluesatvalue = satvalue + difference + (revvalue + difference); |
revvalue = 0; |
} |
else if ((satvalue + difference) < 0) |
{ |
revvaluerevvalue = revvalue + difference + (satvalue + difference); |
satvalue = 0; |
} |
else |
{ |
revvalue += difference; |
satvalue += difference; |
} |
} |
break; |
case "SatisfactionSlider": |
if ((satvalue != ((RadSlider)sender).Value) && (satvalue + 1 != ((RadSlider)sender).Value) && (satvalue - 1 != ((RadSlider)sender).Value)) |
{ |
difference = (satvalue - ((RadSlider)sender).Value) / 2; |
satvalue = ((RadSlider)sender).Value; |
if ((revvalue + difference) < 0) |
{ |
costvaluecostvalue = costvalue + difference + (revvalue + difference); |
revvalue = 0; |
} |
else if ((costvalue + difference) < 0) |
{ |
revvaluerevvalue = revvalue + difference + (costvalue + difference); |
costvalue = 0; |
} |
else |
{ |
revvalue += difference; |
costvalue += difference; |
} |
} |
break; |
} |
} |