How to disable Ajax Slider Extender through Code-Behind

Hi,
I want to disable Ajax Slider Extender through Code behind (with out using Javascript). I tried it by setting the property Enabled="false" for both Slider Extender and TargetControlID but it does'nt work.

MyPage.Aspx
<asp:TextBox ID="txtSlider" Enabled="false" runat="server"></asp:TextBox>
<asp:Label ID="lblSlider" AssociatedControlID="txtSlider" runat="server"></asp:Label>
<ajaxToolkit:SliderExtender ID="MySlider" runat="server" HandleCssClass="Slider_Handle"     TargetControlID="txtSlider" Length="60" Minimum="0" Maximum="1" Decimals="1" BoundControlID="lblSlider" Steps="10" EnableHandleAnimation="true" />

I want something like  MySlider.Enabled = "false" in code-behind.
LVL 1
technodeborahAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

colonel720Commented:
Perhaps when you want the sliderextender to be disabled, set the TargetControlID to a hidden textbox, and then when you want to enable it, put it back to txtSlider
0
technodeborahAuthor Commented:
Hi Colonel720,
If possible, can u provide sample code snippet for this. I tried the solution suggested by you but it didn't work for me.
ThanQ for the reply.
 
0
colonel720Commented:
can you post the code you tried?
(control declarations in the markup, and relevant codebehind)

Thanks
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

technodeborahAuthor Commented:
Hi colonel720,
Following is the code which i tried

<asp:DataList ID="dlstBehavioralParams" runat="server" OnItemDataBound="dlstBehavioralParams_ItemDataBound">
    <ItemTemplate>
          <asp:TextBox ID="txtSlider" Enabled="false" Text='<%# DataBinder.Eval(Container.DataItem, "BPSScore")%>' runat="server"></asp:TextBox>
            <asp:Label ID="lblSlider" AssociatedControlID="txtSlider"  runat="server"></asp:Label>
          <ajaxToolkit:SliderExtender ID="MySlider" runat="server" HandleCssClass="Slider_Handle"
TargetControlID="txtSlider" Length="60" Minimum="0" Maximum="1" Decimals="1"
BoundControlID="lblSlider" Steps="10" />
      </ItemTemplate></asp:DataList>
<asp:TextBox ID="TextBox1" Visible="false" runat="server"></asp:TextBox>
MyPage.aspx.cs:
protected void dlstBehavioralParams_ItemDataBound(object sender, DataListItemEventArgs e)
{
    try
    {
       SliderExtender sldr = (SliderExtender)e.Item.FindControl("MySlider");
       sldr .TargetControlID = TextBox1.ID;
    }
}
0
colonel720Commented:
So you have a datalist of these sliders, and you want to disable all of them by default when the list first loads.
When would the slider be activated? when you want to edit a specific item?
0
technodeborahAuthor Commented:
Hi colonel720,
Based on the logged in user roles the slider will be enabled/disabled

MyPage.aspx.cs:
protected void dlstBehavioralParams_ItemDataBound(object sender, DataListItemEventArgs e)
{
    try
   {
      SliderExtender sldr = (SliderExtender)e.Item.FindControl("MySlider");
       if (Convert.ToBoolean(ViewState["IsSupervisor"].ToString()))
          {
//Here I want the slider to be Enabled.
              TextBox Textsldr = (TextBox )e.Item.FindControl("txtSlider");
               sldr .TargetControlID = Textsldr.ID;

          }
      else
         {
//Here I want the slider to be Disabled (i.e; user is not allowed to change the value).
              sldr .TargetControlID = TextBox1.ID;
         }
    }
}
 
0
colonel720Commented:
Have you tried adding the slider programatically instead of declaritively, for example:

protected void dlstBehavioralParams_ItemDataBound(object sender, DataListItemEventArgs e)
{
    try
  {
      if (Convert.ToBoolean(ViewState["IsSupervisor"].ToString()))
          {
           SliderExtender sldr = new SliderExtender();
           //set properties for sldr here
           e.Item.Cells.Controls.Add(sldr);
          }
    }

}
0
technodeborahAuthor Commented:
Hi colonel720,
 Right now my datalist contains 26 records may be more in future. So I don't want to add it programatically everytime.
0
colonel720Commented:
I don't see why.. If you are concerned about speed, then I would suggest a different way of doing it, as a block of script is added for each record that has a sliderextender and could easily add some 50kb to the httpresponse.

0
technodeborahAuthor Commented:
Sorry !  for the delayed response.
I don't want to add those programatically. I don't know whether it's possible to disable Ajax Slider Extenders from code-behind or not but i will try some other.
Any way ThanQ very much
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.