I have the following Rotator Markup:
and the following Javascript:
First off, the back and First buttons are disabled when the page loads because the user will be on the first "slide". Then I handle the button OnClientClick and, depending on the parameter passed to the handler, I navigate through the Rotator.
Is there a way for me to wire up the "First" and "Last" buttons? I have looked high and low on the telerik site for a way to set the currentIndex of the rotator, but to no avail.
Question 2) I have encountered some strange behavior. I use the rotator ItemShowingHandler to determine the current item index. If it is the first item, I want to disable the "Back" and "First" buttons. If it is the last item, I want to disable the "Next" and "Last" buttons. My code seems to work fine, however what happens is the following. After the page loads, If I click on the "Next" button, everything works as expected. The rotator moves to the second slide, and the "Back" and "First" buttons are enabled. However, if I proceed to click on "Back", a postback occurs. I don't see how this is possible in my code, since I set return false; in the button onClientClick attribute. I notice that if I don't set the button disabled property in the Window on load event, then the postback doesn't occur. The postback occurs whether I set the disabled property in window onload or in code behind in the page load event. Is there something about disabling a button during page load that screws up the OnClientClick Event? Is there another point in which I can disable the buttons to avoid this prior to the page being shown?
<telerik:RadRotator ID="rotGallerySlide" |
runat="server" |
Height="400px" |
Width="500px" |
ItemHeight="400px" |
ItemWidth="500px" |
RotatorType="FromCode" |
OnClientItemShowing="slideShowingHandler_GPC" |
> |
<ItemTemplate> |
some templated controld |
</ItemTemplate> |
</telerik:RadRotator> <
asp:Button ID="btnFirst" runat="server" Text=" << " OnClientClick="navigate_GPC('First'); return false;" style="margin:0px 5px;" /><asp:Button ID="btnBack" runat="server" Text=" < " OnClientClick="navigate_GPC('Back'); return false;" style="margin:0px 5px;" /><asp:Button ID="btnNext" runat="server" Text=" > " OnClientClick="navigate_GPC('Next'); return false;" style="margin:0px 5px;" /><asp:Button ID="btnLast" runat="server" Text=" >> " OnClientClick="navigate_GPC('Last'); return false;" style="margin:0px 5px;" />
|
and the following Javascript:
window.onload = function() { |
setTimeout(function() { |
var firstImg = document.getElementById("<%= btnFirst.ClientId %>"); |
var backImg = document.getElementById("<%= btnBack.ClientId %>"); |
firstImg.disabled = true; |
backImg.disabled = true; |
}, 100); |
} |
function navigate_GPC(navType) { |
var rotator = $find("<%= rotGallerySlide.ClientID %>"); |
switch (navType) { |
case "First": |
break; |
case "Back": |
rotator.showNext(Telerik.Web.UI.RotatorScrollDirection.Right) |
break; |
case "Next": |
rotator.showNext(Telerik.Web.UI.RotatorScrollDirection.Left) |
break; |
case "Last": |
break; |
} |
} |
function slideShowingHandler_GPC(sender, args) { |
var firstImg = document.getElementById("<%= btnFirst.ClientId %>"); |
var backImg = document.getElementById("<%= btnBack.ClientId %>"); |
var nextImg = document.getElementById("<%= btnNext.ClientId %>"); |
var lastImg = document.getElementById("<%= btnLast.ClientId %>"); |
firstImg.disabled = false; |
backImg.disabled = false; |
nextImg.disabled = false; |
lastImg.disabled = false; |
var count = sender.get_items().length; |
var currentIndex = args.get_item().get_index() + 1; |
if
(!sender.isScrollingForward()) { if (currentIndex == 0) { |
firstImg.disabled = true; |
backImg.disabled = true; |
} } |
if (currentIndex == count - 1) { |
lastImg.disabled = true; |
nextImg.disabled = true; |
} |
} |
First off, the back and First buttons are disabled when the page loads because the user will be on the first "slide". Then I handle the button OnClientClick and, depending on the parameter passed to the handler, I navigate through the Rotator.
Is there a way for me to wire up the "First" and "Last" buttons? I have looked high and low on the telerik site for a way to set the currentIndex of the rotator, but to no avail.
Question 2) I have encountered some strange behavior. I use the rotator ItemShowingHandler to determine the current item index. If it is the first item, I want to disable the "Back" and "First" buttons. If it is the last item, I want to disable the "Next" and "Last" buttons. My code seems to work fine, however what happens is the following. After the page loads, If I click on the "Next" button, everything works as expected. The rotator moves to the second slide, and the "Back" and "First" buttons are enabled. However, if I proceed to click on "Back", a postback occurs. I don't see how this is possible in my code, since I set return false; in the button onClientClick attribute. I notice that if I don't set the button disabled property in the Window on load event, then the postback doesn't occur. The postback occurs whether I set the disabled property in window onload or in code behind in the page load event. Is there something about disabling a button during page load that screws up the OnClientClick Event? Is there another point in which I can disable the buttons to avoid this prior to the page being shown?