这里我使用 Asp.Net Ajax SlideShowExtender 控件来创建存储在数据库中的图像的幻灯片放映。该控件使用 GetSlides() Web 服务来检索数据库信息。现在我想将查询字符串传递给 GetSlides() Web 服务,以便图像按照查询字符串中的值旋转。我的困难是如何将查询字符串传递给这个特定的网络服务,我尝试使用“HttpContext.Current.Request.QueryString[“id”]”,但这不起作用,为什么?有人可以建议如何将查询字符串传递到此网络服务。
最佳答案
您应该使用 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 值传递给服务方法。
protected void Page_Load(object sender, EventArgs e)
{
SlideShowExtender1.ContextKey = Request.QueryString["id"];
}
关于c# - 如何将查询字符串传递给 Ajax WebService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1355892/