This is a migrated thread and some comments may be shown as answers.

slider postback not working properly when oneslider's value is affecting another one

1 Answer 113 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Andre Vovan
Top achievements
Rank 1
Andre Vovan asked on 27 Oct 2008, 11:01 PM
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?

<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; 
        } 
    } 

1 Answer, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 29 Oct 2008, 10:17 AM
Hi Peter,
I just answered your support ticket, but I will give the information here as well, so that it is available to all:

***
I could reproduce the problem, only in case you try to set an incorrect value for a RadSlider - in your case all odd numbers are incorrect values. In case you pass only correct values for your sliders, you will not get the second postback.

For example:
protected void RadSlider_ValueChanged(object sender, EventArgs e)  
{  
    RadSlider currSlider = (RadSlider)sender;  
    int currValue = currSlider.Value;  
    int slideStep = currSlider.SlideStep;  
    int difference = 0;  
 
    switch (currSlider.ID)  
    {  
        case "RevenueSlider":  
            if ((revvalue != currValue) &&  
                    (revvalue + slideStep != currValue) &&  
                    (revvalue - slideStep != currValue))  
            {  
                difference = (revvalue - currValue) / 2;  
                revvalue = currValue;  
                if ((costvalue + difference) < 0)  //if any field goes smaller than 0    
                {  
                    satvalue = satvalue + difference + (costvalue + difference);  
                    costvalue = 0;  
                }  
                else if ((satvalue + difference) < 0)  
                {  
                    costvalue = costvalue + difference + (satvalue + difference);  
                    satvalue = 0;  
                }  
                else 
                {  
                    if (difference % 2 != 0)  
                        difference++;  
 
                    costvalue += difference;  
                    satvalue += difference;  
                }  
            }  
            break

I will forward the problem to our developers - that when setting incorrect value to a RadSlider on the server, its server event ValueChange fires, and we will do our best to fix it for Q3, scheduled for next week.
***

Kind regards,
Tsvetie
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Slider
Asked by
Andre Vovan
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Share this question
or