Please Help: Cannot get value

5 posts, 1 answers
  1. Brent
    Brent avatar
    22 posts
    Member since:
    Jan 2009

    Posted 17 Mar 2009 Link to this post

    Hello,

    I am new at programming. I want to email the value of the item selected in RadSlider.

    The RadSlider looks like this:
     <telerik:RadSlider ID="RadSlider1" runat="server" ItemType="Item" Skin="WebBlue"  
                     Width="717px" Height="66px" 
                 OnClientValueChange="UpdateVisibleSlide" OnClientLoaded="UpdateVisibleSlide" 
                  TrackPosition="TopLeft" AppendDataBoundItems="True" Length="720" > 
                    <Items> 
                 <telerik:RadSliderItem Text="Water" Height="100" Value="1"/> 
                 <telerik:RadSliderItem Text="Fire" Value="2" /> 
                 <telerik:RadSliderItem Text="Rock" Value="3"/> 
                 <telerik:RadSliderItem Text="Sun"  Value="4"/> 
                 <telerik:RadSliderItem Text="Earth" Value="5"/> 
                 </Items>  
                  </telerik:RadSlider> 

    I read this forum and followed teh instrcutions in another post about how to get teh value, but it didn't work.

    This is what I wrote:

     Dim mm As New MailMessage() 
            Dim slider As RadSlider = TryCast(RadSlider1.FindControl("rslider"), Telerik.Web.UI.RadSlider) 
            Dim value As Integer = slider.Value 
            Dim routsegid As String = slider.Items(value).Value.ToString() 
            'Assign the MailMessage's properties 
            mm.Subject = "Contact Form" 
           mm.IsBodyHtml = False 
            mm.Body = "The following enquiry has been received from the web on " & DateTime.Now.ToString("D") & ":" & vbCrLf & vbCrLf & _ 
       "Product: " & (slider.Items(value).Value.ToString()) & vbCrLf & vbCrLf & 
                  
            Dim smtp As New SmtpClient 

    The error is saying that
    Line 31:         Dim value As Integer = slider.Value
    System.NullReferenceException: Object reference not set to an instance of an object.
    Please help me make this work. It is probably something simple, but as I said, I am a beginner at this.

    Best,

    Brent.






  2. Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 17 Mar 2009 Link to this post

    Hi Brent,

    The error is due to the fact that the RadSlider control was not correctly referenced and it is null - since you do not have a RadSlider, you cannot get its value.

    However, when I examined your code, I noticed that the RadSlider you have declared has ID=RadSlider1 and after that in the FindControl method you are looking for a RadSlider with ID=rslider. Please, make sure that both IDs are the same, e.g modify your code in the following manner:

    Dim mm As New MailMessage()    
            Dim slider As RadSlider = TryCast(RadSlider1.FindControl("RadSlider1"), Telerik.Web.UI.RadSlider)    
            Dim value As Integer = slider.Value    
            Dim routsegid As String = slider.Items(value).Value.ToString()    
            'Assign the MailMessage's properties    
            mm.Subject = "Contact Form"    
           mm.IsBodyHtml = False    
            mm.Body = "The following enquiry has been received from the web on " & DateTime.Now.ToString("D") & ":" & vbCrLf & vbCrLf & _    
       "Product: " & (slider.Items(value).Value.ToString()) & vbCrLf & vbCrLf &    
                     
            Dim smtp As New SmtpClient    
     


    Best wishes,
    Svetlina
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Brent
    Brent avatar
    22 posts
    Member since:
    Jan 2009

    Posted 17 Mar 2009 Link to this post

    Svetlina,

    Thank you for your help, but I am still getting the same error after changing the code as you suggest.

    The error says the line "Dim value As Integer = slider.Value" is wrong

    Can you please have another look at it? Is there something else wrong? 

    Best,

    Brent


  5. Answer
    Svetlina Anati
    Admin
    Svetlina Anati avatar
    2795 posts

    Posted 18 Mar 2009 Link to this post

    Hi Brent,

    The FindControl method is used for searching the page naming container for a server control with the specified identifier - it is useful in scenarios with INaming Containers as e.g  MasterPage and User Control. You can find more information about it below:

    http://msdn.microsoft.com/en-us/library/31hxzsdw.aspx

    After I again examined your code, I noticed that you have actually used this method of the RadSlider itself - since it is not a container element at all, this usage is incorrect. And since you can reference directly the slider by its ID all you should do is to get the value in the following manner:

     
     
    Dim value As Integer = RadSlider1.Value     


    Sincerely yours,
    Svetlina
    the Telerik team


    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Brent
    Brent avatar
    22 posts
    Member since:
    Jan 2009

    Posted 18 Mar 2009 Link to this post

    Thank you Svetlina! Its working now.

    Brent
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017