Search code examples
c#asp.netajaxweb-servicesslideshow

How to use parameterized function call for ajax slideshow extender?


I am using the ASP.NET ajax slideshow extender tool for displaying images slideshow. I followed the video tutorial and have taken reference from here.

I have the GetSlides function defined as:

public AjaxControlToolkit.Slide[] GetSlides(string parms) {
-----
-----
}

In the aspx page i need to pass the parameter value which is in the query string for that page. The code i used to pass the parameter to the function is:

<ajax:SlideShowExtender ID="SlideShowExtender1" runat="server"
         AutoPlay="true" ImageDescriptionLabelID="lblImageDescription"
               Loop="true" NextButtonID="Btn_Next" PlayButtonID="Btn_Play" 
                PlayButtonText="Play" PreviousButtonID="Btn_Previous" 
                 SlideShowServiceMethod="GetSlides(<%= Request.QueryString["tempID"] %>)" StopButtonText="Stop"
                  TargetControlID="Image1">
</ajax:SlideShowExtender>

However this provides the basic error of server constructs: Server tags cannot contain <% ... %> constructs.

I have checked the expression builder concept also using the text like: "<%$ AppSettings: FooText %>", through web.config. But the parameter is itself dynamic and cannot be stored in web config file. So how should I pass the querystring parameter for the GetSlides function?


Solution

  • You can set parameter from codebehind. Use ContextKey property:

    SlideShowExtender1.ContextKey = Request.QueryString["tempID"];
    

    Also, your method must have signature:

     public AjaxControlToolkit.Slide[] GetSlides(string contextKey)
    

    It's all in docs.