Hi there,
I am trying to make an AjaxToolkit SlideSHow extender work.
The extender sits in a contentpage, with the scriptmanager in the masterpage. The problem seems to be that the private static DataTable declared in the code behind as global, does not keep its data until the page method called by the extender needs it. I put in a gridview just to see if the data comes back from the database, and that works. Also feeding the page method hard coded images works.
The mark up is :
Code:
<asp:Panel ID="Panel1" runat="server">
<asp:Label ID="lblImgTitle" runat="server"></asp:Label>
<asp:Image ID="imgShowImage" runat="server"
Height="300"
Style="border: 1px solid black;width:auto"
AlternateText="" />
<asp:Label runat="server" ID="lblImage"/><br /><br />
<asp:Button runat="server" ID="prevButton" Text="Prev" Font-Size="Larger" />
<asp:Button runat="server" ID="playButton" Text="Play" Font-Size="Larger" />
<asp:Button runat="server" ID="nextButton" Text="Next" Font-Size="Larger" />
<cc1:SlideShowExtender ID="slideshowextend1" runat="server"
ImageTitleLabelID="lblImgTitle"
TargetControlID="imgShowImage"
SlideShowServiceMethod="GetSlides"
AutoPlay="true"
ImageDescriptionLabelID="lblImage"
NextButtonID="nextButton"
PlayButtonText="Play"
StopButtonText="Stop"
PreviousButtonID="prevButton"
PlayButtonID="playButton"
Loop="true"
ContextKey="false"/>
</asp:Panel>
and the code behind is like so
Code:
public partial class Accomodations_Default2 : System.Web.UI.Page
{
private static DataTable photoSlides = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
return;
int AccId = Convert.ToInt32(Request.QueryString.Get("Id"));
//get the slides for the slideshow from the database
//start with declaring variables and parameters
DataTable photoSlides;
SqlDataReader myReader;
SqlParameter AccIdParam;
SqlConnection myCon = new SqlConnection();
//create connection
myCon.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand myCommand = new SqlCommand();
myCommand.CommandText =
"SELECT ToolTip, Description, PhotoUrl FROM Photo2 WHERE (ExternalId = @ExtId) AND (PhotoType = 'Accomodation')";
myCommand.CommandType = CommandType.Text;
myCommand.Connection = myCon;
AccIdParam = new SqlParameter();
AccIdParam = new SqlParameter();
AccIdParam.ParameterName = "@ExtId";
AccIdParam.SqlDbType = SqlDbType.Int;
AccIdParam.Size = 32;
AccIdParam.Direction = ParameterDirection.Input;
AccIdParam.Value = AccId;
myCommand.Parameters.Add(AccIdParam);
myCommand.Connection.Open();
myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
photoSlides = new DataTable();
photoSlides.Load(myReader);
// set the initial image
if (photoSlides.Rows.Count > 0)
{
imgShowImage.ImageUrl = photoSlides.Rows[0]["PhotoUrl"].ToString();
}
GridView1.DataSource = photoSlides;
GridView1.DataBind();
}
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static AjaxControlToolkit.Slide[] GetSlides()
{
//AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[3];
//slides[0] = new AjaxControlToolkit.Slide("../Images/KANO.JPG", "Ascent", "Cool moon night...");
//slides[1] = new AjaxControlToolkit.Slide("../Images/KANO2.JPG", "Desert", "Red moon desert...");
//slides[2] = new AjaxControlToolkit.Slide("../Images/KANO3.JPG", "Tulips", "Beautiful tulips...");
AjaxControlToolkit.Slide[] slides = new AjaxControlToolkit.Slide[photoSlides.Rows.Count];
for (int i = 0; i < photoSlides.Rows.Count; i++)
{
DataRow dr = photoSlides.Rows[i];
slides[i] = new AjaxControlToolkit.Slide(
dr["PhotoUrl"].ToString(),
dr["ToolTip"].ToString(),
dr["Description"].ToString());
}
return slides;
}
}
any suggestions?
best regards, Robin