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

Please Help: Cannot get value

4 Answers 92 Views
Slider
This is a migrated thread and some comments may be shown as answers.
Brent
Top achievements
Rank 1
Brent asked on 17 Mar 2009, 11:07 AM
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.






4 Answers, 1 is accepted

Sort by
0
Svetlina Anati
Telerik team
answered on 17 Mar 2009, 01:29 PM
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.
0
Brent
Top achievements
Rank 1
answered on 17 Mar 2009, 09:42 PM
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


0
Accepted
Svetlina Anati
Telerik team
answered on 18 Mar 2009, 03:31 PM
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.
0
Brent
Top achievements
Rank 1
answered on 18 Mar 2009, 10:51 PM
Thank you Svetlina! Its working now.

Brent
Tags
Slider
Asked by
Brent
Top achievements
Rank 1
Answers by
Svetlina Anati
Telerik team
Brent
Top achievements
Rank 1
Share this question
or