如何将查询字符串传递给Ajax WebService

时间:2009-08-31 05:14:30

标签: c# asp.net asp.net-ajax

这里我使用Asp.Net Ajax SlideShowExtender Control来创建存储在数据库中的图像的幻灯片放映。此控件使用GetSlides()webservice来检索数据库信息。现在我想将一个查询字符串传递给GetSlides()webservice,以便图像像querystring中的值一样旋转。我的困难是如何将查询字符串传递给这个特定的web服务,我尝试使用“HttpContext.Current.Request.QueryString [”id“]”但这不起作用,为什么?有人可以建议如何将查询字符串传递给这个Web服务。

3 个答案:

答案 0 :(得分:3)

您应该使用SlideShowExtender的 ContextKey 功能(请参阅its documentation)。

如果你的扩展器被宣布为样本:

<ajaxToolkit:SlideShowExtender ID="SlideShowExtender1" runat="server" 
  TargetControlID="Image1" 
  SlideShowServiceMethod="GetSlides" 
  AutoPlay="true" 
  ImageTitleLabelID="imageTitle"
  ImageDescriptionLabelID="imageDescription"
  NextButtonID="nextButton" 
  PlayButtonText="Play" 
  StopButtonText="Stop" 
  PreviousButtonID="prevButton" 
  PlayButtonID="playButton" 
  Loop="true" />

您的GetSlides服务方法是使用 contextKey 参数声明的(小心,区分大小写),如下所示:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public AjaxControlToolkit.Slide[] GetSlides(string contextKey) 
{
  // Do something with contextKey here and return the slides.
}

然后你可以在SecondPage.aspx的Page_Load中使用这样的代码将QueryString值传递给service方法。

protected void Page_Load(object sender, EventArgs e) 
{
  SlideShowExtender1.ContextKey = Request.QueryString["id"];
}

答案 1 :(得分:2)

要传递查询字符串,您可以执行类似这样的操作

http://yourpath/service.asmx?imageid=3

要从您的网络服务访问查询字符串,您可以执行此操作

this.Context.Request.QueryString["imageid"];

答案 2 :(得分:0)

相关问题