Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to disable Ajax Slider Extender through Code-Behind

Posted on 2008-11-07
10
Medium Priority
?
2,288 Views
Last Modified: 2013-12-17
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.
0
Comment
Question by:technodeborah
  • 5
  • 5
10 Comments
 
LVL 1

Expert Comment

by:colonel720
ID: 22905436
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
 
LVL 1

Author Comment

by:technodeborah
ID: 22905598
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
 
LVL 1

Expert Comment

by:colonel720
ID: 22905782
can you post the code you tried?
(control declarations in the markup, and relevant codebehind)

Thanks
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:technodeborah
ID: 22906478
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
 
LVL 1

Expert Comment

by:colonel720
ID: 22906591
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
 
LVL 1

Author Comment

by:technodeborah
ID: 22907078
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
 
LVL 1

Expert Comment

by:colonel720
ID: 22907144
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
 
LVL 1

Author Comment

by:technodeborah
ID: 22907301
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
 
LVL 1

Expert Comment

by:colonel720
ID: 22915083
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
 
LVL 1

Accepted Solution

by:
technodeborah earned 0 total points
ID: 23021418
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

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question