在 asp.net 中使用 Ajax 控件工具包并将值传递给数组的 AutoSuggest
这是页面加载
protected void Page_Load(object sender, EventArgs e)
{
if
(Session["useremail"] == null) Response.Redirect("Home.aspx");
else
{
Label8.Text = Session["useremail"].ToString();
}
if (!Page.IsPostBack)
{
TextBox1_AutoCompleteExtender.ContextKey = Label8.Text;
}
}
现在我已将会话 userremail 存储在 TextBox1_AutoCompleteExtender.ContextKey 中。
如何使用以下方法将 TextBox1_AutoCompleteExtender.ContextKey 值传递给变量。
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
string[] movies = { "Joey", "Joester", "Joker", "Joeic", "Joic", "Shrek II" };
return (from m in movies where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
}
我不想传递预定义的数组值,而是想传递数据库表用户中的一列(列名称是名字),我只能使用电子邮件 ID 值对其进行过滤。请帮忙
THis is Page load
protected void Page_Load(object sender, EventArgs e)
{
if
(Session["useremail"] == null) Response.Redirect("Home.aspx");
else
{
Label8.Text = Session["useremail"].ToString();
}
if (!Page.IsPostBack)
{
TextBox1_AutoCompleteExtender.ContextKey = Label8.Text;
}
}
Now I have stored the session useremail in TextBox1_AutoCompleteExtender.ContextKey.
How to use pass the TextBox1_AutoCompleteExtender.ContextKey value to a variable in the below method.
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
string[] movies = { "Joey", "Joester", "Joker", "Joeic", "Joic", "Shrek II" };
return (from m in movies where m.StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) select m).Take(count).ToArray();
}
Instead of passing that array value predefined I want to pass a column from the database table user (column name is firstname) i can filter it only with the email id value. Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过在包含 GetCompletionList(...) 方法的 Web 服务中启用会话状态来解决此问题,以便您可以以与 ASP.NET Web 应用程序/站点中相同的方式访问用户的电子邮件地址。
默认情况下,Web 方法的会话支持处于关闭状态。您必须通过将 WebMethod 特性的 EnableSession 属性设置为 true 来为每个 Web 方法显式启用它。启用后,您可以按照您在 ASP.NET 中习惯的方式访问会话状态。
例如:有关
WebMethodAttribute 的 EnableSession 属性的详细信息,请参见:
http://msdn.microsoft.com/en-us/library/system.web.services.webmethodattribute.enablesession.aspx
请注意,如果Web 服务的客户端(消费者)使用 cookie 来维护会话状态,因此它们必须支持 HTTP cookie。对于现代浏览器来说应该没问题(我认为这是您的主要客户)。
需要有关在 Web 服务中使用 ASP.NET Session 的更多信息吗?只需转到 MSDN 上的以下链接:
http://msdn.microsoft.com/ en-us/library/aa480509.aspx
You can solve this by enabling session state in your web service which contains the GetCompletionList(...) method so that you can access the user's email address in the same fashion as in your ASP.NET Web application / site.
By default, session support is turned off for a web method. You must explicitly enable it for each web method by setting the EnableSession property of the WebMethod attribute to true. When enabled you can access the session state in the same manner as you are accustomed to in ASP.NET.
For example:
More information on the EnableSession property of the WebMethodAttribute can be found here:
http://msdn.microsoft.com/en-us/library/system.web.services.webmethodattribute.enablesession.aspx
Be aware that if the clients (consumers) of your web service use cookies to maintain the session state, that they must support HTTP cookies. Should be no problem for modern browsers (which I assume are your main clients).
More information needed about using ASP.NET Session in a web service? Just go to the following link on MSDN:
http://msdn.microsoft.com/en-us/library/aa480509.aspx