Hi,


I made a UserControl called SliderUserControl which contains two labels and a WebSlider (third party slider control) in a table. The labels left and right of the slider should give the value of the slider and (Maximum - value) of the slider respectively. So if the slider goes from 0-100 and is at 30 now, then the control looks like this:
Code:
30  ----|---------- 70
I accomplished this with some simple javascript, and it's all working just fine:
asp Code:
  1. <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="SliderUserControl.ascx.vb" Inherits="F1TimeTrials.Controls.SliderUserControl" %>
  2. <%@ Register assembly="Infragistics35.Web.v10.2, Version=10.2.20102.1011, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.Web.UI.EditorControls" tagprefix="ig" %>
  3.  
  4. <script type="text/javascript" id="igClientScript">
  5. <!--
  6.  
  7.     function sliderControl_ValueChanged(sender, eventArgs) {
  8.         var leftLabel = document.getElementById('<%= Me.lblLeftValue.ClientID %>');
  9.         var rightLabel = document.getElementById('<%= Me.lblRightValue.ClientID %>');
  10.  
  11.         var maxValue = sender.get_maxValueAsDouble();
  12.         var value = eventArgs.get_newValue();
  13.         leftLabel.innerHTML = value;
  14.         rightLabel.innerHTML = maxValue - value;
  15.     }// -->
  16. </script>
  17.  
  18. <asp:Table ID="table" runat="server">
  19.     <asp:TableRow runat="server">
  20.  
  21.         <asp:TableCell runat="server">
  22.             <asp:Label runat="server" ID="lblLeftValue" Text="0" />
  23.         </asp:TableCell>
  24.  
  25.         <asp:TableCell runat="server">
  26.             <ig:WebSlider ID="sliderControl" runat="server">
  27.                 <ClientEvents ValueChanged="sliderControl_ValueChanged" />
  28.             </ig:WebSlider>
  29.         </asp:TableCell>
  30.  
  31.         <asp:TableCell runat="server">
  32.             <asp:Label runat="server" ID="lblRightValue" Text="100"/>
  33.         </asp:TableCell>
  34.  
  35.     </asp:TableRow>
  36. </asp:Table>
In order to interact with the WebSlider third party control directly I made some 'pass-through' properties such as MaxValue, MinValue, etc:
vb.net Code:
  1. Imports Infragistics.Web.UI.EditorControls
  2.  
  3. Namespace Controls
  4.  
  5.     Public Class SliderUserControl
  6.         Inherits System.Web.UI.UserControl
  7.  
  8.         Public ReadOnly Property Slider As WebSlider
  9.             Get
  10.                 Return Me.sliderControl
  11.             End Get
  12.         End Property
  13.  
  14.         Public Property Value As Object
  15.             Get
  16.                 Return Me.Slider.Value
  17.             End Get
  18.             Set(ByVal value As Object)
  19.                 Me.Slider.Value = value
  20.             End Set
  21.         End Property
  22.  
  23.         Public Property MinValue As Object
  24.             Get
  25.                 Return Me.Slider.MinValue
  26.             End Get
  27.             Set(ByVal value As Object)
  28.                 Me.Slider.MinValue = value
  29.             End Set
  30.         End Property
  31.  
  32.         Public Property MaxValue As Object
  33.             Get
  34.                 Return Me.Slider.MaxValue
  35.             End Get
  36.             Set(ByVal value As Object)
  37.                 Me.Slider.MaxValue = value
  38.             End Set
  39.         End Property
  40.     End Class
  41. End Namespace

Anyway, as I said, this works fine. If I use a Register directive that points to the SliderUserControl.ascx source then I can use it on my page and it works.


However, I actually need three different kind of sliders, each slightly different from this 'base' slider. For example, one will work with integers, another will work with float point values, etc. So what I want to do is create three classes that inherit SliderUserControl, and customize it from there.

So, for example, a slider that goes from 1 to 11 with only one label (without the extra second label on the right) could look like this:
vb.net Code:
  1. Imports Infragistics.Web.UI.EditorControls
  2.  
  3. Namespace Controls
  4.  
  5.     Public Class NormalSlider
  6.         Inherits SliderUserControl
  7.  
  8.         Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  9.             If Not Me.IsPostBack Then
  10.                 Me.Slider.ValueType = SliderValueType.Int
  11.                 Me.Slider.MinValue = 1
  12.                 Me.Slider.MaxValue = 11
  13.                 Me.Slider.Value = 6
  14.                 Me.Slider.SmallChange = 1
  15.                 Me.Slider.LargeChange = 3
  16.                 Me.Slider.Tickmarks.NumberOfMajorTickmarks = 3
  17.                 Me.Slider.Tickmarks.NumberOfMinorTickmarks = 11
  18.  
  19.                 Me.lblLeftValue.Text = "6"
  20.                 Me.lblRightValue.Visible = False
  21.             End If
  22.         End Sub
  23.  
  24.     End Class
  25. End Namespace

And now I'm a little stuck... I can build this project, but the NormalSlider control does not show up in the toolbox as I'm used to from windows forms projects.
I thought well, that's probably different for ASP.NET, but then I remembered that it DOES work for a different control. I have a class Grid that inherits a third party UltraWebGrid control:
vb.net Code:
  1. Imports Infragistics.WebUI.UltraWebGrid
  2.  
  3. Namespace Controls
  4.     Public Class Grid
  5.         Inherits Infragistics.WebUI.UltraWebGrid.UltraWebGrid
  6.    
  7.         '...
  8.     End Class
  9. End Namespace
When I build the project now, the Grid control does show up in the toolbox! So that's a bit strange...


However, I googled the problem of course and I figured out how to get a custom control (class inheriting a control) onto a page, and apparently I can use another Register directive where I need to specify the Assembly and the Namespace. As far as I know, the Assembly is just the current project (the control is not in a separate project) called F1TimeTrials, and the Namespace is either Controls or F1TimeTrials.Controls.

So I tried both of those, for example:
asp Code:
  1. <%@ Register TagPrefix="uc" Assembly="F1TimeTrials" Namespace="F1TimeTrials.Controls" %>

Now, I can type "<uc:" and Intellisense shows me the NormalSlider control. Great! However, when I place it on the page, it does not show up during design-time. There's just nothing there.
asp Code:
  1. <%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="SliderTest.aspx.vb" Inherits="F1TimeTrials.SliderTest" %>
  2.  
  3. <%@ Register TagPrefix="uc" Assembly="F1TimeTrials" Namespace="F1TimeTrials.Controls" %>
  4.  
  5.  
  6.  
  7. <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
  8. </asp:Content>
  9. <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  10.  
  11.     <!-- ScriptManager required for the WebSlider third party control -->
  12.     <asp:ScriptManager runat="server">
  13.     </asp:ScriptManager>
  14.  
  15.     <!-- Slider: -->
  16.     <uc:NormalSlider runat="server" ID="slider1" />
  17.  
  18. </asp:Content>

There are no warnings or errors or anything, but the control isn't there.

When I run the project, it throws a null-reference exception in the Page_Load event of the NormalSlider class. Apparently, Slider (= the WebSlider third party control on the base class) is Nothing.

I don't get it... How can it be Nothing in the Page_Load event? Should I call some method that creates the control in the base-class first? Or ..?!

Does anyone see what I'm doing wrong?