Page view counter

SlideShowExtender and database integration, c# newbie

Last post 04-03-2008 1:37 AM by rfurdzik. 18 replies.

Sort Posts:

  • SlideShowExtender and database integration, c# newbie

    03-07-2007, 6:46 AM
    • Loading...
    • weriax
    • Joined on 03-07-2007, 11:20 AM
    • Posts 3
    • Points 1

    hi there

    i'm having trouble reading values from my database with the slideshowextender

    my images are stored in a database, so i read them from there and display them. all working 100%. the catch is i need to send through a parameter with a refno that must be sent to sql, but the Request[] statement doesn't work.

    how do i send through a request parameter to my webmethod?

    my code:

     <ajaxToolkit:SlideShowExtender runat="Server" ID="sseImages" TargetControlID="imgMain" NextButtonID="btnNext" PreviousButtonID="btnPrev" SlideShowServiceMethod="GetSlides" Loop="true" />

     

    [System.Web.Services.

    WebMethod]

    [System.Web.Script.Services.

    ScriptMethod]

    public static AjaxControlToolkit.Slide[] GetSlides()

    {

    string RefNo = Request["RefNo"];

    SqlConnection dbConn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConn"].ConnectionString);

    SqlCommand cmdImages = new SqlCommand();

    cmdImages.Connection = dbConn;

    cmdImages.CommandType =

    CommandType.StoredProcedure;

    cmdImages.CommandText =

    "getPropertyMainImages";

    cmdImages.Parameters.AddWithValue(

    "@RefNo", RefNo);

    dbConn.Open();

    SqlDataReader dreImages = cmdImages.ExecuteReader();

    AjaxControlToolkit.

    Slide[] mySlides = new AjaxControlToolkit.Slide[10];

    dreImages.Close();

    dreImages = cmdImages.ExecuteReader();

    int i = 0;

    while (dreImages.Read())

    {

    mySlides[i] =

    new AjaxControlToolkit.Slide("displayImage.aspx?Type=Main&PImageKey=" + dreImages["PropertyImageKey"], "Image 1", "Image 1");

    i++;

    }

    dreImages.Close();

    cmdImages.Dispose();

    dbConn.Close();

    return mySlides;

    }

     

  • Re: SlideShowExtender and database integration, c# newbie

    03-07-2007, 7:45 PM
    • Loading...
    • kirtid
    • Joined on 11-18-2006, 12:41 AM
    • Redmond
    • Posts 658
    • Points 2,610
    This sounds very similar to the autocompleteextender issue. Please open a new work item for this for the SlideShowExtender as well. Thanks!
    Kirti Deshpande
    Program Manager, Silverlight and ASP.NET AJAX
    Microsoft

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: SlideShowExtender and database integration, c# newbie

    03-08-2007, 6:05 AM
    Answer
    • Loading...
    • msiggi
    • Joined on 08-28-2006, 12:07 PM
    • Germany
    • Posts 6
    • Points 34

    Hello,

    I had the same Problem and I solved it in this way (I dont´t know if it is the best):

    I played around to debug the GetSlides()-Webservice and tried to get a parameter in the Webservice (e.g. the database-ID of the Photo-Album) per Request.QueryString - and so it works for me:

    1 Set the SlideShowServiceMethod dynamically in the Code-Behind:

    <ajaxToolkit:SlideShowExtender ID="Slideshowextender" runat="server" PreviousButtonID="Button1" 
            NextButtonID="Button3" PlayButtonID="Button2" TargetControlID="Image_Slideshow" 
            SlideShowServiceMethod="" PlayInterval="5000" PlayButtonText="Play" StopButtonText="Stop"></ajaxToolkit:SlideShowExtender>
    
    

    protected void Page_Load(object sender, EventArgs e)

    {

    // AlbumID for Slideshow:

    Slideshowextender.SlideShowServiceMethod =

    "GetSlides?AlbumID="+ Request.QueryString["AlbumID"];  
    ...
    2 And in The GetSlides-Webservice:
    
    

    [System.Web.Services.

    WebMethod]

    [System.Web.Script.Services.

    ScriptMethod]

    public static AjaxControlToolkit.Slide[] GetSlides()

    {

    int AlbumID = int.Parse(HttpContext.Current.Request.QueryString["AlbumID"]);

     

    // now the Database-Select with the Parameter:

    Hope That helps!

    Marcel

  • Re: SlideShowExtender and database integration, c# newbie

    03-08-2007, 6:50 AM
    • Loading...
    • weriax
    • Joined on 03-07-2007, 11:20 AM
    • Posts 3
    • Points 1

    hi marcel

    thanks for you reply. i also found a workaround:

    string

    RefNoQuerystring = HttpContext.Current.Request.UrlReferrer.Query

     which returns all the query parameters of the referring URL, and then i just extracted the string i needed with a small function. but your way seems a bit cleaner!

     thanks for your help

    werner

  • Problems with Slide Control

    07-05-2007, 4:02 PM
    • Loading...
    • rfurdzik
    • Joined on 07-01-2002, 2:32 PM
    • zikbay.com
    • Posts 1,720
    • Points 3,427

     

    I had the same problem. Thaks for the fix. The problem is that the webservice is static and can not access properties from the instance of the page... Here is more info: http://west-wind.com/weblog/ShowPost.aspx?id=8282

    Do you guys know how to change the full path of the pticture? The problem is that with UR Rerwiter this does not work at all! The Slides Extender adds path to the existing original path request instead of to the rewritten one! So I am getting this URL:

    http://localhost/mysite/Ad/PhotoDisplay.ashx?size=full&photoid=375 instead of this one http://localhost/site/PhotoDisplay.ashx?size=full&photoid=375 

    It is using the source URL path! http://localhost/mysite/Ad/ It should use the rewritten one: http://localhost/mysite/

    Rafal
    Zikbay.com - Free Classifieds
    (Search Over 5 mln jobs on Zikbay.com)


    DNN Direct
  • Re: Problems with Slide Control

    07-05-2007, 4:52 PM
    • Loading...
    • kirtid
    • Joined on 11-18-2006, 12:41 AM
    • Redmond
    • Posts 658
    • Points 2,610

    The SlideShow extender webservice now takes in additional context. If you take a look at the sample website demo we document that and there are examples in the SampleWebsite and Toolkit tests project that demonstrate how to use that parameter.

    Kirti Deshpande
    Program Manager, Silverlight and ASP.NET AJAX
    Microsoft

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Problems with Slide Control

    07-05-2007, 6:23 PM
    • Loading...
    • rfurdzik
    • Joined on 07-01-2002, 2:32 PM
    • zikbay.com
    • Posts 1,720
    • Points 3,427

    kirtid:

    The SlideShow extender webservice now takes in additional context. If you take a look at the sample website demo we document that and there are examples in the SampleWebsite and Toolkit tests project that demonstrate how to use that parameter.

    Thanks, a lot

     I am not sure how this is an answer to my question. It seems that Slides extender is using original URL path, instead of the rewritten one. How sendding additional string parameter can help here? Is there a property I can set for the base URL, so it does not use the current original URL? It would be also nice if I can provide full URL to my pictures, but extender adds the base path (wrong) in the background.... Did you guys test it with URLRewriter? 

    This is what I currently get with Extender using URLRewriter:

    1 Link: original Link: http://localhost/mysite/Ad/118 Rewritten link: http://localhost/mysite/ShowAd.aspx?id=118

    2) Extender shows pictures as:http://localhost/mysite/Ad/PhotoDisplay.ashx?size=full&photoid=360; This is what ist should be: http://localhost/mysiste/PhotoDisplay.ashx?size=full&photoid=362

      Here is my code just in case:

        [System.Web.Services.WebMethod]
        [System.Web.Script.Services.ScriptMethod]
        public static AjaxControlToolkit.Slide[] GetSlides()
        {
    
            // Check if the URL querystring contains a valid ad.
            
            int aid = DefaultValues.IdNullValue;
            string adIdQs = HttpContext.Current.Request.QueryString["AdID"];
            if (adIdQs != null && !Int32.TryParse(adIdQs, out aid))
            {
                HttpContext.Current.Response.Redirect("~/Search.aspx");
            }
    
            //int aid = 121; //hardcoded value just for testing
            //int aid = AdId; //This wan't work as the webservice MUSt be static and AdId is Instance method..
    
            AdsDataComponent.PhotosDataTable dreImages = PhotosDB.GetPhotosByAdId(aid) as AdsDataComponent.PhotosDataTable;
            AjaxControlToolkit.Slide[] mySlides = new AjaxControlToolkit.Slide[dreImages.Count];
           
             if (dreImages != null)
            {
                int i = 0;
    
                foreach (AdsDataComponent.PhotosRow photo in dreImages)
                {
                    string ImageUrl = "PhotoDisplay.ashx?size=full&photoid=" + photo.Id.ToString();
                   
                    mySlides[i] =
                        new AjaxControlToolkit.Slide(ImageUrl, "Image 1", "Image 1");
                    i++;
                }
    
            }
    
            return mySlides;
    
                   
    
        }
    }
     

     

    Rafal
    Zikbay.com - Free Classifieds
    (Search Over 5 mln jobs on Zikbay.com)


    DNN Direct
  • Re: Problems with Slide Control

    07-05-2007, 6:59 PM
    • Loading...
    • kirtid
    • Joined on 11-18-2006, 12:41 AM
    • Redmond
    • Posts 658
    • Points 2,610

    I see. This deviates from the general question of the thread. I was referring to the earlier question of passing additional data to the webservice. I will point David to this thread since he knows more about url rewriting.

    Kirti

    Kirti Deshpande
    Program Manager, Silverlight and ASP.NET AJAX
    Microsoft

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Problems with Slide Control

    07-05-2007, 7:06 PM
    • Loading...
    • rfurdzik
    • Joined on 07-01-2002, 2:32 PM
    • zikbay.com
    • Posts 1,720
    • Points 3,427

    Thanks a lot. I will put this under a seperate thread.

    Rafal
    Zikbay.com - Free Classifieds
    (Search Over 5 mln jobs on Zikbay.com)


    DNN Direct
  • Re: Problems with Slide Control

    07-05-2007, 7:37 PM
    Answer
    • Loading...
    • David Anson
    • Joined on 04-11-2006, 1:39 AM
    • Microsoft
    • Posts 1,842
    • Points 8,710

    SlideShow seems to support full URLs in the Slide constructor. For example, if I add the following line to the GetSlides method in SlideShow.aspx (10618 release), I see the new image fine:

    new AjaxControlToolkit.Slide("http://www.live.com/live/1.900.9.001/img/wl_jewel.gif", "Windows flag", "Windows flag"),

    As such, if you return the URL-remapped paths to your images from your web service I'd expect it to work. Could you maybe try this again?


    http://blogs.msdn.com/delay

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Problems with Slide Control

    07-05-2007, 7:43 PM
    • Loading...
    • rfurdzik
    • Joined on 07-01-2002, 2:32 PM
    • zikbay.com
    • Posts 1,720
    • Points 3,427

    David, thanks for your reply. OK, I was not sure if it supports. I will put the full path now and let you know if it works.

    I have to find out first how to get the full path to my root directory in the webservice....

    Rafal
    Zikbay.com - Free Classifieds
    (Search Over 5 mln jobs on Zikbay.com)


    DNN Direct
  • Re: Problems with Slide Control

    07-05-2007, 8:35 PM
    • Loading...
    • rfurdzik
    • Joined on 07-01-2002, 2:32 PM
    • zikbay.com
    • Posts 1,720
    • Points 3,427

    OK, the full path works fine, you guys still should fix the relative path problem with URL rewriter...

    public static AjaxControlToolkit.Slide[] GetSlides()

    {

    // Check if the URL querystring contains a valid ad.

     

    int aid = DefaultValues.IdNullValue;

    string adIdQs = HttpContext.Current.Request.QueryString["AdID"];

    if (adIdQs != null && !Int32.TryParse(adIdQs, out aid))

    {

    HttpContext.Current.Response.Redirect("~/Search.aspx");

    }

    //int aid = 121; //hardcoded value just for testing

    //int aid = AdId; //This wan't work as the webservice MUSt be static and AdId is Instance method..

    AdsDataComponent.PhotosDataTable dreImages = PhotosDB.GetPhotosByAdId(aid) as AdsDataComponent.PhotosDataTable;

    //AjaxControlToolkit.Slide mySlides = new AjaxControlToolkit.Slide();

    AjaxControlToolkit.Slide[] mySlides = new AjaxControlToolkit.Slide[dreImages.Count];

     

     

    // ArrayList myList = new ArrayList();

    //int i;

     

    //for(i=0; i<5; i++)

    // myList.Add(i);

     

    //myList.Add("Hello");

     

    //for(i=0; iConsole.WriteLine("Array Index [{0}]: {1}", i, myList[i].ToString());

     

     

    if (dreImages != null)

    {

    int i = 0;foreach (AdsDataComponent.PhotosRow photo in dreImages)

    {

    StringBuilder ImageUrl = new StringBuilder();

    if (ClassifiedsHttpApplication.SiteUrl != null)

    {

    ImageUrl.Append(
    ClassifiedsHttpApplication.SiteUrl);

    if (!ClassifiedsHttpApplication.SiteUrl.EndsWith("/"))

    ImageUrl.Append("/");ImageUrl.Append("PhotoDisplay.ashx?size=full&photoid=");

    ImageUrl.Append(photo.Id.ToString());

    }

    //string ImageUrl = "PhotoDisplay.ashx?size=full&photoid=" + photo.Id.ToString();

     

    mySlides[i] =

    new AjaxControlToolkit.Slide(ImageUrl.ToString(), "Image 1", "Image 1");

    i++;

    }

    }

    return mySlides;

    // return new AjaxControlToolkit.Slide[] {

    // new AjaxControlToolkit.Slide("images/Blue hills.jpg", "Blue Hills", "Go Blue"),

    // new AjaxControlToolkit.Slide("images/Sunset.jpg", "Sunset", "Setting sun"),

    // new AjaxControlToolkit.Slide("images/Winter.jpg", "Winter", "Wintery..."),

    // new AjaxControlToolkit.Slide("images/Water lilies.jpg", "Water lillies", "Lillies in the water"),

    // new AjaxControlToolkit.Slide("images/VerticalPicture.jpg", "Sedona", "Portrait style picture")};

    //}

     

    }

    Rafal
    Zikbay.com - Free Classifieds
    (Search Over 5 mln jobs on Zikbay.com)


    DNN Direct
  • Re: SlideShowExtender and database integration, c# newbie

    01-11-2008, 6:10 AM
    • Loading...
    • kamalsran
    • Joined on 12-21-2007, 5:32 AM
    • Posts 108
    • Points 60

    give me code to make slide show extender

    thax
    http://developersaspdotnet.blogspot.com/

  • Re: SlideShowExtender and database integration, c# newbie

    02-12-2008, 2:38 PM
    • Loading...
    • barthsm
    • Joined on 09-16-2007, 7:21 PM
    • Orchard Park, NY
    • Posts 12
    • Points 14

    Thanks so much for your post, Marcel (Aug of 2006). It was a long time ago, but your method worked for me - I've been looking all over on how to get a parameter passed to the GetSlides() method.  I couldn't get the contextkey to work, so this was a great solution; thank you!
     

  • Re: SlideShowExtender and database integration, c# newbie

    02-19-2008, 5:36 AM
    • Loading...
    • mhkdas123
    • Joined on 02-19-2008, 10:33 AM
    • Posts 3
    • Points 6

    Hi, Can I get complete Code with Handler  you used?

     

Page 1 of 2 (19 items) 1 2 Next >