Ajax Slider format value to currency - lost on postback

Last post 07-31-2009 5:41 PM by StuartH. 3 replies.

Sort Posts:

  • Ajax Slider format value to currency - lost on postback

    07-31-2009, 7:39 AM
    • Member
      23 point Member
    • StuartH
    • Member since 07-20-2005, 6:03 PM
    • Posts 27

    Hi,

    I've got a Slider that is used to select a loan amount between 10000 and 100000 (code below). I wanted to display the value selected on the slider in GBP in the format: £10,000 etc. I used the following post to add Javascript code (script below) to achieve this and this works fine:

     http://forums.asp.net/p/1175047/1976782.aspx#1976782

    However, further down my form there is a dropdownlist that performs a postback when the selected value is changed. This postback causes the formatted currency value from my slider (displayed in 'display') to be reset. Any ideas on how I can get round this?

    The javascript I added:

    function pageLoad() {
                    $find('formatcurrency').add_valueChanged(onSliderValueChanged);
                }
              
    function onSliderValueChanged(){
    
                   var value = $find('formatcurrency').get_Value();
                    
                   // Code to manipulate value to new value in correct format - 'newvalue' 
                
               document.getElementById('display').innerHTML = newvalue
               
              
                }
    
     
    My code:
    
     <asp:TextBox ID="loanamount" CssClass="slidertextbox" runat="server"></asp:TextBox>
                                               
     <cc1:SliderExtender runat="server" ID="SliderExtender1"  
      TargetControlID="loanamount" Decimals="0" Length="200" BehaviorID="formatcurrency"  Minimum="10000" Steps="19" Maximum="100000"   
     EnableHandleAnimation="true" /> 
    
    <b id="display" style="width: 60;" class="sliderloan"></b>
     
    Many Thanks
    StuartH


     

     

     

  • Re: Ajax Slider format value to currency - lost on postback

    07-31-2009, 11:07 AM
    Answer
    • Member
      158 point Member
    • Jester98x
    • Member since 01-12-2007, 5:16 PM
    • Sussex, UK
    • Posts 29

    Replace <b id="display"> with a server control, e.g. <asp:label id="display" runat="server" CssClass="sliderloan" />. On postback put the value back into the label.

    Don't forget to update document.getElementById('display').innerHTML = newvalue  

    to 

    $find('display').innerHTML = newvalue  

  • Re: Ajax Slider format value to currency - lost on postback

    07-31-2009, 5:05 PM
    • Member
      23 point Member
    • StuartH
    • Member since 07-20-2005, 6:03 PM
    • Posts 27

    Hi, I've tried adding this as a asp:label control as suggested, but the label text is not getting updated as the slider changes (this is even before the postback of the dropdownlist, just moving the slider doesn't update the text).

    Any ideas?

    Thanks

    StuartH

  • Re: Ajax Slider format value to currency - lost on postback

    07-31-2009, 5:41 PM
    • Member
      23 point Member
    • StuartH
    • Member since 07-20-2005, 6:03 PM
    • Posts 27

    Hi, did manage to get this to work with: 

    $get'<%=display.ClientID %>').innerHTML = display;

    Thanks very much for your solution.

Page 1 of 1 (4 items)