Wednesday, March 21, 2012

Delete Image from slideshow

Hi there,

I have copied the slideshow example and modified it to suit my purposes. I am stuck however on a problem.

I want to be able to press a button and delete an image from the slideshow. I know how to create the delete statement I just don't know how to get the value from the image into the statement.

Im using XML to store the location information of the images

<?xml version="1.0" encoding="utf-8"?>
<customer>
<header>
</header>
<slides>
<slide imagePath="\AjaxShaneSite\SlideShow\images\Blue hills.jpg" name="1" description="This is blue" />
<slide imagePath="\AjaxShaneSite\SlideShow\images\sunset.jpg" name="2" description="sunset" />
<slide imagePath="\AjaxShaneSite\SlideShow\images\water lilies.jpg" name="4" description="water lillies" />
<slide imagePath="\AjaxShaneSite\SlideShow\images\winter.jpg" name="5" description="winter...." />

</slides>
</customer>

Name equals the images ID.

This is my webmethod for the slide show

public partial class _Default : System.Web.UI.Page
{
// protected System.Web.UI.WebControls.DropDownList DropDownList1;
// Get the SQL Connection string from the web.config.
public String strConnectSQL = (ConfigurationSettings.AppSettings["csMain"]);

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static AjaxControlToolkit.Slide[] GetSlides()
{
XmlDocument myXML = new XmlDocument();
myXML.Load("H:\\AjaxShaneSite\\Slides.xml");
int i = 0;
AjaxControlToolkit.Slide[] temp = new AjaxControlToolkit.Slide[myXML.SelectSingleNode("/customer/slides").ChildNodes.Count];
foreach (XmlNode xNode in myXML.SelectSingleNode("/customer/slides").ChildNodes)
{
temp[i] = new AjaxControlToolkit.Slide(
xNode.Attributes["imagePath"].Value,
xNode.Attributes["name"].Value,
xNode.Attributes["description"].Value);
i++;
}
return temp;
}

Can anyone suggest some way for me to get the value from the image that is currently been displayed within the show?

Any help would be great!

Thanks

Shane

You can set the behavior id on the slideshow and retrieve the image element and get the source from that.

Something like this:

var slideshowbehavior = $find('slideshowbehavior1');

var image = slideshowbehavior.get_element();

var imageurl = image.src;


Sorry to be sounding daft here but where do I place this code?

Think I need a dummies guide to .NET & AJAX


In a client side function that responds to the slide changed event.

Check out this post:http://forums.asp.net/thread/1627419.aspx. It talks about getting the current slide.


Hi again,

Sorry I am really battling with this one.

I have a form that is in a master page. I have add your script to my page but nothing happens.

This is my update.

<%@. Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ItemDetails.aspx.cs" Inherits="_Default" Title="RMH - Item Details" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <script type="text/javascript">function addSlideShowHandlers() {// hook into the slide show change eventvar slideshow = $find("slideShowBehavior1");slideshow.add_slideChanged(setCurrentSlide);}function setCurrentSlide(sender, eventargs) {var label = $get('label1');label.innerText = eventargs.ImagePath; }</script> <table style="width: 100%; height: 100%" onload="addSlideShowHandlers()"> <tr> <td style="width: 10%;"> </td> <td style="width: 35%;"> </td> <td style="width: 55%;"> </td> <td style="width: 10%;"> </td>
....
...
..
<cc1:slideshowextenderid="slideshowextend1"runat="server"autoplay="true"imagedescriptionlabelid="imageLabel1"BehaviorID="slideShowBehavior1"loop="true"nextbuttonid="nextButton"playbuttonid="playButton"playbuttontext="Play"previousbuttonid="prevButton"slideshowservicemethod="GetSlides"stopbuttontext="Stop"targetcontrolid="Image1"></cc1:slideshowextender>

</td><tdstyle="width: 55%;">

</td><tdstyle="width: 10%;"></td></tr></table>

Copyright

<br/>

</

asp:Content>

Any ideas?


I was having the same problem you are having and finally realized that since I am using Master Pages, I have to put the <bodyonload="addSlideShowHandlers()"> statement in the body tag on the Matser Page. Once I did that, it worked like a charm.

Hope that helps.


I've seen a number of threads such as this one discussing how to retrieve the current slide from the extender. I need to set the current slide so that the slide show begins from a designated index inside the slides array.

I am developing a rudimentary understanding of using behaviorID to hook into the various methods inside the javascript used to implement the extender but don't yet have enough of an understanding of what I'm seeing to figure out how to pass an index in and have the slideshow initialize at that point in the array rather than the beginning.

Any assistance is greatly appreciated!


For people using masterpages and trying the onload you might need to register the onload even in your child page. Make sure in your master page you've got the body tag set to runat="server" and give it an id="yourname". The example code below uses the body tag ID ="MainBody".

(inside the childpage's Page_Load event)

HtmlGenericControl body = (HtmlGenericControl)Page.Master.FindControl("MainBody");

body.Attributes.Add("onload","LoadBase()");

---

Doin the above means you will not have to register the code in your masterpage.

No comments:

Post a Comment